Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Animation problem

Posted on 2003-03-07
3
Medium Priority
?
220 Views
Last Modified: 2010-03-31
Hello,

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?
0
Comment
Question by:jmgww
  • 2
3 Comments
 
LVL 2

Accepted Solution

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

 ... draw and stuff .....

long after = System.currentTimeInMillis();

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


hope this helps..
0
 

Author Comment

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

Author Comment

by:jmgww
ID: 8093385
Nice one, thanks!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

564 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