Animation problem

Posted on 2003-03-07
Medium Priority
Last Modified: 2010-03-31

I'm having an unusual problem with an animation sequence.
Basically I have a Swing timer updating an image (moves it 1px every 40ms). The problem is, it moves the images about 5px, stops for about half a second, and this repeats. The only other Thread I have created is one that implements Runnable and only refreshes itself every 250ms. The CPU usage is at 100% when this Applet is run.

Whats UNUSUAL is that when I reload the applet a few times using the Applet Viewer it starts behaving normaly and CPU usage drops. Any ideas whats going on here?
Question by:jmgww
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

antonsigur earned 90 total points
ID: 8091701
I would take System.currentTimeInMillis() before movement and calculations, then again after, then sleep the diffrence...
long before = System.currentTimeInMillis();

 ... draw and stuff .....

long after = System.currentTimeInMillis();

if (40 - (after - before) > 0)
  sleep(40 - (after - before));
  immidiate calculations...();

hope this helps..

Author Comment

ID: 8093384
That's great, I'll give it a try, thanks

Author Comment

ID: 8093385
Nice one, thanks!!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question