This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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: 64115
215
  • 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: 64115
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!