Solved

stop a Timer

Posted on 2004-10-18
13
230 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 100 total points
ID: 12337026
updateTimer.stop();
0
 
LVL 37

Assisted Solution

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

(cancel() is for java.util.Timer)
0
Technology Partners: 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!

 
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 100 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

688 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