import javax.sound.sampled.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.FlowLayout;
class MusicPaly extends JFrame
{ private Clip clip;
JButton button=new JButton("暂停");
MusicPaly()
{
setBounds(100,200,200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try
{
InputStream stream=new FileInputStream("5.wav");
AudioInputStream audioStream=AudioSystem.getAudioInputStream(stream);
clip =AudioSystem.getClip();
clip.open(audioStream);
clip.start();
}
catch(Exception er){}
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(button.getText().equals("暂停"))
{
clip.stop();
button.setText("重新开始");
}
else
{
clip.start();
button.setText("暂停");
}
}
});
setLayout(new FlowLayout());
add(button);
setVisible(true);
}
public static void main(String[] args)
{
new MusicPaly();
}
}
|