Results 1 to 13 of 13
- 06-29-2010, 08:58 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Please help!!!! how to kill Timer listener?
Does anyone know how to kill following Timer listener action? i have tried very hard, but still duno how to kill it..:(
Thanks
--------------------------------------------------------------------------------
int timeRemaining =10;
int timing=60000;
Timer countdownTimer = new Timer(timing, new CountdownTimerListener()); // Initial game time
public void CountDownTimer(int timing, int timeRemaining) {
System.out.println("countdown time");
if ( countdownTimer.isRunning())
{
System.out.println("is running - inside ");
countdownTimer.stop();
}
else
{
System.out.println("no running - inside ");
countdownTimer.start();
}
}
class CountdownTimerListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
--timeRemaining;
if (timeRemaining ==5)
{
String timervalue=String.valueOf(timeRemaining);
System.out.println(timervalue);
timeRemaining=10;
}
else if (timeRemaining >5) {
String timervalue=String.valueOf(timeRemaining);
System.out.println("timeRemaining"+timeRemaining);
System.out.println("show only");
}
else if (timeRemaining==11) {
System.out.println("stop only");
countdownTimer.stop();
}
else {
System.out.println("timeRemaining"+timeRemaining);
timeRemaining=10;
countdownTimer.stop();
} }
}
???
- 06-29-2010, 09:31 AM #2
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 06-29-2010, 09:35 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
since no ppl can answer there, so i post it here..sorry for any inconvenice cause
- 06-29-2010, 09:55 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 26
- Rep Power
- 0
use the .kill() method
- 06-29-2010, 10:19 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
i used java.1.5 and javax.swing.Timer dun have .kill() method
only have removeActionListener(ActionListener listener)
Thanks
-
1) Agree with Phil: please notify us if you cross-post the same question. No one likes risking duplication of effort when the question may have already been answered elsewhere.
2) What do you mean by "kill" and what is the problem with your current code? Errors? Non-functioning? Other?
Perhaps you need to get the reference to your Timer object before calling stop from ActionEvent's getSource() method? But I honestly don't know given info as provided.
- 06-29-2010, 03:33 PM #7
Have you looked at the Timer class to see if there is a method to do what you want?
How about the removeActionListener() method?
- 06-29-2010, 04:16 PM #8
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Fubarable :
1. noted! sorry abt that. wont do this next time.
2. Well! i hope i can remove the timer listener when calling another class object, and another class inside have the timer listener as well.
Currently when i calling anther class, its trigger another Timer listener, i hope i can remove/kill the first Timer b4 calling the second class object.
- 06-29-2010, 04:22 PM #9
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Norm:
Yes. i have looked the method inside JAVA API, and found the removeActionListener() method. i have hard, but still idea how to apply this removeaction method in my code.
--> ?????
public void removeActionListener(ActionListener listener)
{
CountdownTimerListener .remove(ActionListener.class, listener);
} <---? am i code it correctly?
Thanks alot
- 06-29-2010, 04:57 PM #10
You need a reference to the Timer object and a reference to the listener.how to apply this removeaction method in my code.
timerRef.removeActionListener(refToListener);
- 06-29-2010, 05:22 PM #11
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Hi Norm:
this is my timer object ->
Timer countdownTimer = new Timer(timing, new CountdownTimerListener()); // Initial game time
so i shd code as
countdownTimer.removeActionListener(countdownTimer );
??
Thanks alot!
-
Why would you want to remove the ActionListener? I don't see what purpose that would serve. Wouldn't stopping the Timer simply be enough?
- 06-29-2010, 06:05 PM #13
Similar Threads
-
kill a thread
By Peter in forum Advanced JavaReplies: 6Last Post: 06-22-2010, 08:08 AM -
Kill sessions
By Subscribe.name in forum Java ServletReplies: 1Last Post: 10-05-2009, 10:22 PM -
How I launch an external program and kill the father?
By Dr_Misterio in forum New To JavaReplies: 2Last Post: 08-05-2009, 03:31 PM -
Identify and kill forked jvm (ant java task)
By stockbroker in forum Advanced JavaReplies: 1Last Post: 04-09-2009, 06:27 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks