ラベルを毎秒更新するJavaSwingタイマーがあります。タイマーを開始した後、ラベルは毎秒更新され、すべてが正常に機能します。
次に、実行ごとに変化するランダムな時間間隔の後、ラベルの更新が停止します。タイマー更新コードにブレークポイントを設定しましたが、トリガーされなくなりました。
また、通常はタイマーを停止するすべての場所にログステートメントを配置しましたが、それらの場所はどれも呼び出されません。
何が問題なのですか?
編集:これがコードのサンプルです
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent arg0) {
secondsRemaining--;
System.out.println("Seconds remaining:" + secondsRemaining);
//update the progressbar
double initialLength = currentSettings.getLength()*60;
double progress = (initialLength - secondsRemaining)/initialLength ;
progressBarTime.setProgress(progress);
//update the progress label
progressPercentage.setText(((int)(progress * 100)) + "%");
if (secondsRemaining >= 0) {
updateTimeRemaining(secondsToString(secondsRemaining));
} else {
System.out.println(">0 seconds TIMER STOPPED with the number of seconds = " + secondsRemaining);
treatmentTimer.stop();
// set the status to Finished
currentState = State.FINISHED;
}
}
}
そしてタイマーの初期化:
tTimer = new Timer(1000, actionListener);
tTimer.start();
奇妙なことに、プログラムはJRE 7u7がインストールされたPCで正常に動作します。つまり、タイマーがラベルを正常に更新しますが、7u10を搭載した2台のPCで試しましたが、このタイマー停止の問題は両方で発生します。