0
我想停止使用JButton
的音頻流,我怎麼能做到這一點?我想讓音頻停止與JButton,我該怎麼做?
這裏是我的代碼:
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
public class twerk {
Thread thread;
static int loo = 1;
static File fl = new File("MYFILE");
public static void frame(){
JFrame frame = new JFrame("COLLIN");
frame.setSize(1086,800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
ImageIcon image = new ImageIcon("MYPICTURE");
JLabel label = new JLabel(image);
frame.add(label, BorderLayout.NORTH);
frame.setIconImage(image.getImage());
JButton button = new JButton("Stop Sound");
frame.add(button, BorderLayout.SOUTH);
frame.setVisible(true);
}
public static void PlayClip(){
try
{
String st =fl.getPath();
InputStream in = new FileInputStream(st);
AudioStream au = new AudioStream(in);
AudioPlayer.player.start(au);
if(loo == 1){
Thread.sleep(1900);
PlayClip();
}
} catch(Exception e){}
}
public static void main(String[] args){
frame();
PlayClip();
}
}
我想停止非盟這樣一個ActionListener:
static class Action implements ActionListener{
public void actionPreformed (ActionEvent e){
AudioPlayer.player.stop();
}
我會怎麼做。也許我可以做類似
if(JButton.clicked){
audiostream.player.stop
}
任何輸入將不勝感激!
你的歌聲,你的圖形用戶界面在不同的線程運行,則必須中斷其他線程,請遵循Java代碼convetions – nachokk
請注意,我們並不需要在大膽的聲明,以閱讀它們! –
我不明白爲什麼ü具有可變線程你不使用它..你用凍結你的Thread.sleep貴,你做遞歸調用同一個函數.. – nachokk