如何将播放/暂停按钮添加到以下代码?
import javazoom.jl.player.Player;
try{
FileInputStream fis = new FileInputStream("mysong.mp3");
Player playMP3 = new Player(fis);
playMP3.play();
}
catch(Exception exc){
exc.printStackTrace();
System.out.println("Failed to play the file.");
}
Run Code Online (Sandbox Code Playgroud) 我有一个工作得很好的音乐播放器,但我想添加一个播放/暂停按钮。我已经设置了按钮等,但我不知道实际暂停剪辑的代码。
这是我的代码:
try{
File f = new File("songs/mysong.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.getAudioInputStream(f);
clip.open(ais);
playing = true;
if(MusicPlayer.pause)
{
clip.stop(); // <- Doesnt stop the song
}
clip.loop(Clip.LOOP_CONTINUOUSLY);
}catch(Exception exception){System.out.println("Failed To Play The WAV File!");}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我想要做的是将按钮放在应用程序的左下角.有人可以给我一个如何做的例子吗?
这就是我所拥有的:

这是我的代码:
super("Test");
/**Create Components**/
JPanel addPanel = new JPanel();
JButton addButton= new JButton("Add");
/**Add Components**/
addPanel.add(addButton);
this.add(addPanel);
/**Set Components Properties**/
addButton.setLocation(12, 371);
addButton.setPreferredSize(new Dimension(116, 40));
addPanel.setLocation(12, 371);
addPanel.setPreferredSize(new Dimension(116, 40));
/**Frame Properties**/
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setPreferredSize(new Dimension(dimension1, dimension2));
this.setResizable(false);
this.pack();
this.setVisible(true);
Run Code Online (Sandbox Code Playgroud) 嘿,我只需要一个问题解答...我如何使以下代码不冻结我的整个JFrame?
try {
Thread.sleep(Integer.parseInt(delayField.getText()) * 1000);
System.out.println("Hello!");
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
Run Code Online (Sandbox Code Playgroud)