I have a timer set up to run constinuously every few seconds. It's working fine. However, I want to add a new button that makes the timer go exactly 10 times. So I wrote:
The timer itself if supposed to output text to the screen. But I end up getting 0,1,...,9, and then one set of the print out of the timer. It looks like the timer doesn't actually start until all the code in that method is executed, at which point the timer will start only once. I'm interested in the outputed data on the 10th iteration. How should I go about getting it? Thanks Alot! Kate
I think you want the restart() method after the first time...
[ September 24, 2004: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Jan 29, 2003
Are you using java.util.Timer? You can tell Timer to call a task object at some interval. In the task object you can count how many times it has been run. After 10 times it can call cancel on itself. Does that fit your needs?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Feb 11, 2004
Thanks to all the help, I finally got my timer to work exactly 10 times! Although I'm still stuck with a major problem. I am calling three function, like this:
Each method has a print statement in its body. When I run this code, I get the following output: inside clear method inside verify method inside timer.start action <- this one is repeated 10 times, obviously.
Why are my methods not executed in the order I write them in?! Why is it that no matter the order in my code, and how many lines, and pauses I add in my code, timer.start always get executed last?
Please help me out on this one, I can't even begin to understand how I can possibly change this annoying behavior!!! Sigh.