Java Reference
In-Depth Information
{
clip = getAudioClip(
new URL(getDocumentBase(),
"cuckoo.wav"));
}
catch(MalformedURLException muEx)
{
System.out.println("*** Invalid URL! ***");
System.exit(1);
}
play = new JButton("Play");
play.addActionListener(this);
stop = new JButton("Stop");
stop.addActionListener(this);
loop = new JButton("Loop");
loop.addActionListener(this);
buttonPanel = new JPanel();
buttonPanel.add(play);
buttonPanel.add(stop);
buttonPanel.add(loop);
add(buttonPanel,BorderLayout.SOUTH);
}
public void stop()
{
clip.stop(); //Prevents sound from continuing
} //after applet has been stopped.
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == play)
clip.play();
if (event.getSource() == stop)
clip.stop();
if (event.getSource() == loop)
clip.loop();
}
}
Here's the code for the minimal Web page that will be used to contain the applet:
<HTML>
<APPLET CODE="SimpleSoundApplet.class"
WIDTH = 300
HEIGHT = 200>
</APPLET>
</HTML>
Search WWH ::




Custom Search