Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Pausing for "animation"  RSS feed

 
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.
 
Bartender
Posts: 4179
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.
 
Marshal
Posts: 61710
193
  • 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.
 
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: 61710
193
  • 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!