JavaSwing实现简单的音乐播放停止

import java.applet.Applet;
import java.applet.AudioClip;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Ta extends JFrame{
public static void main(String[] args) {
new Ta();
}
private AudioClip audio;
int i=0;
public Ta() {
JButton jb1 = new JButton(“点击”);
this.audio = Applet.newAudioClip(Ta.class.getResource(“1.wav”));
this.audio.loop();
this.add(jb1);
jb1.addActionListener((e)->{
if(i%2==0)
{
this.audio.stop();
i++;
}
else
{
this.audio.loop();
i++;
}
});
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setSize(300, 300);
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注