大神们,请教下为什么Eclipse运行没有报错,但是点击了“Dou”按钮却没有反应(没有声音),急死我了!!
package b16;
import sun.audio.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.Clip;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class b16 extends JFrame implements ActionListener{
JButton []jb = new JButton[]{new JButton("Dou"),new JButton("Ruai"),new JButton("Mi"),new JButton("Fa"),new JButton("Sou"),new JButton("La"),new JButton("Xi")};
private Clip clip;
public b16() throws IOException, UnsupportedAudioFileException, LineUnavailableException{
super("音阶程序");
JPanel app = new JPanel(new GridLayout(1, 7));
Container c = super.getContentPane();
super.setLocation(400,400);
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
super.setSize(600, 150);
super.setResizable(false);
super.setVisible(true);
c.add(app);
for(int i = 0;i < 7;i++) { //添加音阶播放按钮
app.add(jb[i]);
}
InputStream test = new FileInputStream("C:\\Users\\911\\Desktop\\Dou.wav");
BufferedInputStream test1 = new BufferedInputStream(test);
AudioInputStream as = AudioSystem.getAudioInputStream(test1);
clip=AudioSystem.getClip();
clip.open(as);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb[0]) {
clip.start();
clip.stop();
}
}
public static void main(String[] args) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
b16 test = new b16();
}
}