Solved

stop a Timer

Posted on 2004-10-18
13
225 Views
Last Modified: 2010-03-31
Hi,

I wanna know how can I stop a timer from the timer's ActionListener??

here is my codes...

javax.swing.Timer updateTimer = new javax.swing.Timer(500, new UpdateListener());

class UpdateListener implements ActionListener
{
  public void actionPerformed(ActionEvent ae)
  {
    if ( Condition == true)
      // I want to stop updateTimer here, how can I do so????
  }
}




Xenia
0
Comment
Question by:xenia27
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
cancel()
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
updateTimer.stop();
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 100 total points
Comment Utility
Sorry: stop()

(cancel() is for java.util.Timer)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you'll need to make your UpdateListener class an inner class of the one that defines updateTimer.
0
 
LVL 13

Assisted Solution

by:Webstorm
Webstorm earned 100 total points
Comment Utility
Hi

updateTimer.stop()

0
 

Author Comment

by:xenia27
Comment Utility
I guess, I need to make updateTimer be a global...^^"
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
Or you can pass it to your actionlistener subclass as a parameter, and store it in a member variable
0
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
class UpdateListener implements ActionListener
{
    Timer timer;
    public UpdateListener(Timer timer)
    {this.timer=timer;}
...
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> I guess, I need to make updateTimer be a global...^^"

not if you make your UpdateListener class an inner class of the one that defines updateTimer.
0
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
>> not if you make your UpdateListener class an inner class of the one that defines updateTimer.

and if the UpdateListener class is a static inner class, updateTimer must also be static.
0
 

Author Comment

by:xenia27
Comment Utility
OK...got this work perfectly~  Thanks~~~~
0
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
:-) glad your problem is solved
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now