import javax.swing.*;
import java.applet.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class LoadAudioAndPlay extends JApplet{
AudioClip sound1,sound2,currentsound;
JButton playsound,loopsound,stopsound;
JComboBox choosesound;
URL url1,url2;
String name[]={"Welcome","hi"};
public void init(){
Container c=getContentPane();
c.setLayout(new FlowLayout());
choosesound=new JComboBox(name);
try{
sound1=Applet.newAudioClip(getClass().getResource("w.wav"));
sound2=Applet.newAudioClip(getClass().getResource("y.wav"));
}catch(Exception e){
e.printStackTrace();}
currentsound=sound1;
choosesound.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
currentsound.stop();
currentsound=choosesound.getSelectedIndex()==0 ?
sound1 : sound2;
}
});
c.add(choosesound);
playsound=new JButton("Paly");
c.add(playsound);
loopsound=new JButton("Loop");
c.add(loopsound);
stopsound=new JButton("Stop");
c.add(stopsound);
ButtonActionHandler handler=new ButtonActionHandler();
playsound.addActionListener(handler);
loopsound.addActionListener(handler);
stopsound.addActionListener(handler);
}
private class ButtonActionHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==playsound)
currentsound.play();
if(e.getSource()==loopsound)
currentsound.loop();
if(e.getSource()==stopsound)
currentsound.stop();
}
}
public static void main(String[] args){
LoadAudioAndPlay m=new LoadAudioAndPlay();
JFrame app=new JFrame("AudioAndPlay Test");
m.init();
m.start();
app.getContentPane().add(m);
app.setBounds(100,100,400,100);
app.setVisible(true);
}
}
请大家帮忙指教一下这是什么原因 谢谢!万分感激!!