• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer.start issues

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


[ September 24, 2004: Message edited by: marc weber ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic