掌握APPLET基本结构及影音展示

    技术2022-05-11  154

    APPLET  与 JAPPLETfish 发表于 2005-10-18 9:25:20 实验九   APPLET  与 JAPPLET 1.实验目的:     掌握APPLET基本结构及影音展示 2.实验内容:     使用JAVA编写一包含四个按钮,分别控制声音、图象的APPLET 3.实验步骤: //Tup.java: import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; import java.net.*; public class Tup extends JApplet implements ActionListener{ JButton jb1,jb2,jb3,jb4; Panel p1,p2; Image image; AudioClip ad1;     int k=0; // Component gp1=new GlassPane(); public void init() { try{ go(); } catch(Exception e){ e.printStackTrace(); } } public void go() throws Exception{ this.setSize(new Dimension(500,700)); this.setBackground(Color.blue); this.setForeground(Color.red); Font t=new Font("华文行楷",Font.PLAIN,14); this.setFont(t); p1=new Panel(); p2=new Panel(); URL url=new URL(getCodeBase().toString()+"/images/"); image=getImage(url,"009.jpg");         ad1=getAudioClip(url,"yy.mid"); p1.setLayout(new FlowLayout()); jb1=new JButton("播放声音"); jb2=new JButton("停止播放"); jb3=new JButton("显示图象"); jb4=new JButton("关闭图象"); jb1.addActionListener(this); jb2.addActionListener(this); jb3.addActionListener(this); jb4.addActionListener(this); p1.add(jb1,null); p1.add(jb2,null); p1.add(jb3,null); p1.add(jb4,null); getContentPane().add(p1,BorderLayout.NORTH); //getContentPane().add(p2,BorderLayout.CENTER); } public void actionPerformed(ActionEvent ae){ String s=ae.getActionCommand(); if(s.equals("播放声音")){ ad1.play(); ad1.loop(); } if(s.equals("停止播放")){ ad1.stop(); } if(s.equals("显示图象")){     k=1;     repaint();     } if(s.equals("关闭图象")){ k=0; repaint(); } } public void paint(Graphics g) { if(k==1){     g.drawImage(image,53,20,this);         }     else     if(k==0){     g.clearRect(0,0,500,700);     g.drawString("Hello",191,211);     } }   }

    最新回复(0)