• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pausing for "animation"  RSS feed

 
Duncan MacFarland
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to be able to show a set of pictures that would result in a primitive sort of animation. I'd like to do something lighter than making my thread sleep. Is there a way to pause the code without pausing the thread, other than something like a for-next loop of 1 to 2000 just to take up time? Thanks.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes look at the Timer classes. I think there are two one in java.util and one in javax.swing I think. (I would look it up but am on the phone now). You would use one of those to schedule a change to happen at some defined interval, and provide a task to execute at that interval.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beware: Last time I tried anything big in Swing, it took something like 30ms for the display to repaint itself. Which means that running the Timer every 20ms may result in frames being missed out. Computer have got a lot faster since then, so that problem may not apply any more.

I think it will be the Swing timer you want. There are actually three Timers in the Java7 API. That is the bad news. The good news, however, is that the Java Tutorials tells you all about Swing timers.
 
Ken Duncan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the responses. This is helpful.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!