Solved

stop a Timer

Posted on 2004-10-18
13
229 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
printf performancy 11 86
Eclipse with various Java releases 7 48
Using jdbcTemplate.batchUpdate to improve INSERT performance 6 27
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 …
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 “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…
This video teaches viewers about errors in exception handling.

749 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