Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer / Thread question" Watch "Timer / Thread question" New topic

Timer / Thread question

Brad Murphy

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

Joined: Feb 18, 2003
Posts: 4
okay, thanks Chris
I agree. Here's the link:
subject: Timer / Thread question
jQuery in Action, 3rd edition