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
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");
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.