source file name: AppletSoundProgram.java
First download below Sound files.
/*
<applet code=AppletSoundProgram.class width=300 height=300 >
</applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AppletSoundProgram extends Applet implements ActionListener
{
Button play,stop;
AudioClip audioClip;
// String str="audiotest.au";
String str="DBJ Abhimaan1.wav";
public void init()
{
audioClip = this.getAudioClip(this.getDocumentBase(), str );
}
public AppletSoundProgram()
{
play = new Button("Play");
stop = new Button("Stop");
add(play);add(stop);
play.addActionListener(this);
stop.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if (s.equals("Play"))
{
audioClip.play();
}
if(s.equals("Stop"))
{
audioClip.stop();
}
}
}
output:
click on button Play you hear sound/music
4 Comments
Very good blog sir. It is really helpful for students as it clears basic knowledge.
ReplyDeleteThanks
ReplyDeleteGreat experience with this site. Its very useful for every student who wants the proper knowledge of programming.
ReplyDeleteThank you for your encouraging words.
DeletePost a Comment