-
September 24th, 2011, 10:10 AM
#1
Why the applet can not play sound?
//Here is the code,Could anybody help me find out why it does not work? Thank you!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example10_3 extends Applet implements ActionListener
{ AudioClip clip;
Button buttonPlay,
buttonLoop,
buttonStop;
public void init()
{ clip=getAudioClip(getCodeBase(),"ding.Wav");
//have ding.wav file in the same directory with the applet
buttonPlay=new Button("Play");
buttonLoop=new Button("Replay");
buttonStop=new Button("Stop");
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
}
public void stop()
{ clip.stop();
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==buttonPlay)
{ clip.play();
}
else if(e.getSource()==buttonLoop)
{ clip.loop();
}
if(e.getSource()==buttonStop)
{ clip.stop();
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|