Reputation: 148
I have been trying to stop the timer and solve this for days now, unfortunately no luck, hope someone will be able to help.
The idea is to use the timer to click a button which increases the value in the text field so I have the timer in the start button and I wish to stop it in the stop button.
That's the code I have behind my start button:
private void btStartTimerActionPerformed(java.awt.event.ActionEvent evt) {
javax.swing.Timer tm = new javax.swing.Timer(100, new ActionListener(){
public void actionPerformed(ActionEvent evt) {
btAddOneActionPerformed(evt);
}
});
tm.start();
private void btStopTimerActionPerformed(java.awt.event.ActionEvent evt) {
}
Upvotes: 2
Views: 103
Reputation: 168845
The solution to this is in keeping a reference to the Timer
object that is created. For more info. see The Java™ Tutorials - Classes and Objects: Declaring Member Variables.
Upvotes: 2