Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Thread trouble

 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an image viewer program in which I use a label with an Icon to view images. The left and right navigation buttons work, but I what I really want is a startShow and stopShow buttons. The startShow btn should iterate through all the images automatically with a 2 second pause starting with the current one and stopShow button should stop the show at the present image. If I add no pause, it actually works but is too fast. If I add a pause, it doesn't display any images. What am I doing wrong?
Here is some of the relevant code.
 
Kathy Walrath
Author
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're waiting in the event thread, which stops all event-processing and painting in the app. What you should use instead is a Swing Timer. You can find information about Swing Timers here:
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
In fact, there's some code in there which is very close to what you need -- it performs an action once a second for as long as there's anything to do.
[ April 29, 2004: Message edited by: Kathy Walrath ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic