aspose file tools*
The moose likes Java in General and the fly likes Timer.start issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer.start issues" Watch "Timer.start issues" New topic
Author

Timer.start issues

Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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.

Thanks Alot,
Kate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timer.start issues
 
Similar Threads
Message doesnt display continuously
Timer Trouble
slowing down movement in an applet.... doesn't have anything to do with the applet.
Java Threads: wait+notify
Threads, and the UI question.