xenia27
asked on
stop a Timer
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(ActionEven t ae)
{
if ( Condition == true)
// I want to stop updateTimer here, how can I do so????
}
}
Xenia
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(ActionEven
{
if ( Condition == true)
// I want to stop updateTimer here, how can I do so????
}
}
Xenia
cancel()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you'll need to make your UpdateListener class an inner class of the one that defines updateTimer.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I guess, I need to make updateTimer be a global...^^"
Or you can pass it to your actionlistener subclass as a parameter, and store it in a member variable
class UpdateListener implements ActionListener
{
Timer timer;
public UpdateListener(Timer timer)
{this.timer=timer;}
...
{
Timer timer;
public UpdateListener(Timer timer)
{this.timer=timer;}
...
> 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.
not if you make your UpdateListener class an inner class of the one that defines updateTimer.
>> 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.
and if the UpdateListener class is a static inner class, updateTimer must also be static.
ASKER
OK...got this work perfectly~ Thanks~~~~
:-) glad your problem is solved
Thanks