• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread.sleep or javax.swing.Timer  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have an application, where I need to apply a pause between repaints.
Currently I'm using Thead.sleep(..) before I do a repaint, but I noticed with another program of mine that the gui buttons become non-responsive while using sleep, so on that program I switched to javax.swing.Timer, and everything worked.

In this program, I'm only using a small delay, eg Thread.sleep(20),
which maybe why I can still use the buttons, however when I use the Acclerator key for items on menu, it seems to give a slight extended delay between the repaints at the moment I press the key. Perhaps using Timer will stop this.

Any thoughts? Thanks
[ September 18, 2007: Message edited by: colin shuker ]
 
Brandon Broschinsky
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing exactly what you are doing, I would lean toward using javax.swing.Timer. If you use sleep(); you will be blocking the EVT which you probably don't want to be doing.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read a lot of books, done a lot of contemplation, only to find out later there is a layer on the bottom of the Crystal Blue Lagoon at Camp Code Puppies - goinig by the moniker: LOVEABLE CRUMUDGEONS

Test, test, test.

Do what the testing shows is actually going on.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javax.swing.Timer doc makes some reference to the java.util.Timer and a couple places to learn how to decide which one to use when. Besides actually working correctly, either Timer does a lot of thread work for you and is much easier on the next person who has to read the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!