?
Solved

stop a Timer

Posted on 2004-10-18
13
Medium Priority
?
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12337024
cancel()
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 12337026
updateTimer.stop();
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 400 total points
ID: 12337031
Sorry: stop()

(cancel() is for java.util.Timer)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Expert Comment

by:objects
ID: 12337034
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 400 total points
ID: 12337038
Hi

updateTimer.stop()

0
 

Author Comment

by:xenia27
ID: 12337040
I guess, I need to make updateTimer be a global...^^"
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 12337043
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
ID: 12337048
class UpdateListener implements ActionListener
{
    Timer timer;
    public UpdateListener(Timer timer)
    {this.timer=timer;}
...
0
 
LVL 92

Expert Comment

by:objects
ID: 12337050
> 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
ID: 12337060
>> 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
ID: 12337069
OK...got this work perfectly~  Thanks~~~~
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 12337073
:-) glad your problem is solved
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12337273
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 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