[英]swing.Timer does not stop
我在所有班級中都使用swing.Timer,但在所有計時器中都遇到了相同的問題,問題是:我的所有計時器第一次都運行良好,但是第二次所有計時器都沒有停止
這是我所有計時器的代碼
Timer timer1;
S= 0 ;
ActionListener taskPerformer2 ; = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if ( S == 10 ){
// My work
timer1.stop();
}
S++;
System.out.println(S + "A");
};
};
timer1 = new Timer(20, taskPerformer2);
timer1.start();
直接從事件中檢索當前計時器。
public void actionPerformed(ActionEvent evt) {
if ( S == 10 ){
// My work
((Timer)evt.getSource()).stop(); // <-- this was changed
}
S++;
System.out.println(S + "A");
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.