This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer / Thread question

 
Brad Murphy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, thanks Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic