applet程序如下:import java.applet.*; import javax.swing.*; import java.awt.event.*;public class PlayIt extends JApplet { public void init() { //Get the sound clip clip = getAudioClip(getDocumentBase(), "music.wav"); //Create the clip
//Rest of the applet initialization... myButton = new JButton(play); myButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(play)) { clip.loop(); myButton.setText(stop); } else { clip.stop(); myButton.setText(play); } } }); getContentPane().add(myButton); } AudioClip clip; JButton myButton; final String play = "PLAY"; final String stop = "STOP"; }
import javax.swing.*;
import java.awt.event.*;public class PlayIt extends JApplet
{
public void init()
{
//Get the sound clip
clip = getAudioClip(getDocumentBase(), "music.wav"); //Create the clip
//Rest of the applet initialization...
myButton = new JButton(play); myButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals(play))
{
clip.loop();
myButton.setText(stop);
}
else
{
clip.stop();
myButton.setText(play);
} }
}); getContentPane().add(myButton);
}
AudioClip clip;
JButton myButton;
final String play = "PLAY";
final String stop = "STOP";
}