[英]swing.Timer does not stop
I use swing.Timer in all my classes , and I got same problem in the all timers the problem is : all my timers work good for first time , but in second time all timers they are not stop 我在所有班级中都使用swing.Timer,但在所有计时器中都遇到了相同的问题,问题是:我的所有计时器第一次都运行良好,但是第二次所有计时器都没有停止
this the code for all my timers 这是我所有计时器的代码
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();
Retrieve the current timer from the event directly. 直接从事件中检索当前计时器。
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.