我想在執行函數mediaPlayer()之前顯示一個文本。在媒體播放器的執行過程中,我睡着了線程。沒關係,因爲什麼都不需要發生(然後只需要聽)。睡眠一個java線程,但首先更新jFrame
但是,上一個文本:「收聽...」,沒有顯示(除了延遲幾秒鐘)。有沒有辦法在線程進入休眠之前先刷新jFrame?
expText.setText("Listen to the song and give a rating when it finishes.");
startButton.setEnabled(false);
//play sound
try {
mediaPlayer();
//wait for the duration of the stimuli
Thread.sleep(stimDuration);
...
是:永遠不要在UI線程上進行長時間運行的操作。在後臺線程上調用'mediaPlayer'或將其重寫爲異步。 – 2015-02-09 19:28:10
你不想把SwingWorker包裝在一個Timer中,這只是......很奇怪。只需使用SwingWorker來播放音頻。看看[這個例子](http://stackoverflow.com/questions/24274997/java-wav-player-adding-pause-and-continue/24275168#24275168) – MadProgrammer 2015-02-09 20:23:47
什麼mediaPlayer和單桅帆船它工作?延遲的目的是什麼? – MadProgrammer 2015-02-09 20:28:44