我希望在此GUI中有几个按钮可以播放多个声音,同时编辑文本文件,以便下次程序运行时,播放时播放的歌曲仍在播放。到目前为止我已经收到了一首歌,但它不会打开并给我这个错误。我已经很久没有编写java了,所以我觉得我错过了一些愚蠢的东西。
代码
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class AddSound extends JFrame {
JButton Play = new JButton("Play");
JButton Loop = new JButton("Loop");
JButton Stop = new JButton("Stop");
URL music1 = AddSound.class.getResource("music1.wav");
AudioClip clip = Applet.newAudioClip(music1);
public AddSound() {
super("AddingSound");
setLayout(new FlowLayout());
Play.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clip.play();
}
});
Loop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clip.loop();
}
});
Stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clip.stop();
}
});
add(Play);
add(Loop);
add(Stop);
}
public static void main(String args[]) {
JFrame frame = new AddSound();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(90, 90);
frame.setVisible(true);
}
}