wood burning stoves 2.0*
The moose likes Java in General and the fly likes Timer / Thread question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer / Thread question" Watch "Timer / Thread question" New topic
Author

Timer / Thread question

Brad Murphy
Greenhorn

Joined: Feb 18, 2003
Posts: 4
I'm creating an application that will act as a Stopwatch. It will have a card layout with three cards. The first will be a clock, the second will be a stopwatch, and the third will be a timer that counts backwards until reaching 0.
Can someone please give me a little advise with regards to the threads? At first I was thinking about creating a different thread for each of the cards (3 timers). Now I'm thinking about creating one swing timer in a swingworker object, and using the invokeLater method to update all three cards.
Does that sound like a good idea, or am I way off?
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
seems like the easiest thing to do would be to just use a single thread of your own creation(not the one created by the window). You could set your run method to execute every second(or maybe half second to be sure you get time changes closer to the actual time tic). Inside the run method call the update for each of your time displays(time,count up,count down). Each time display would need to check itself for invalid values (like less than zero for the count down).
Something along those lines is how I would do it.
Hope this helps.
Brad Murphy
Greenhorn

Joined: Feb 18, 2003
Posts: 4
okay, thanks Chris
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Timer / Thread question
 
Similar Threads
new Thread freezes up program
help with Java timer
Instantiate a class
advice sampling thread
Repainting JPanel