Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer.start issues

 
Kate Zoy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you want the restart() method after the first time...


[ September 24, 2004: Message edited by: marc weber ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kate Zoy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic