Buffering and Threads in Animations using Java
 
 
 
This 3-Dimensional rotating logo will run quite slowly to begin with, until all the frames in the animation sequence have been downloaded to the user's computer.
 
The playing of the animation can be paused and resumed by mouse-clicking on the logo.
 
The animated logo was created as a movie file in .AVI format using the program Asymetric 3D F/X.  Then the animation frames were captured individually and converted to .JPG graphics file format using Paint Shop Pro.  There are 32 different frames in the sequence.  A Java program controls the loading and playing of the animation.


Java Programming Notes:
This Java Applet displays an animation which loops indefinitely.  It uses double buffering, which means that as one frame is being displayed on the screen, the next one is being prepared in the background using an Image buffer.  Double buffering is used to avoid screen flicker while the next image is being prepared.  The Image method getGraphics associates the Graphics object being drawn with the Image buffer.

Because this animation uses the Runnable interface with Threads, when the user moves to another Web Page, the playing of the animation is stopped and the Thread is terminated, thus saving processor time.  If the user then revisits the page, a new Thread is started and the animation begins playing immediately because the images are still loaded in memory.  By comparison, a GIF animation on a Web Page continues to run in the background when the user switches to another window, thus degrading the computer's performance.

The mouseDown method allows the user to click on the image to control the animation using the Thread methods suspend and resume.

The MediaTracker is used to prevent partial images from being displayed.  Whereas partial display is a useful technique for progressively displaying large images as they download, in an animated graphic during the initial loading of the frames in the sequence, partial display would disturb the smoothness of the movement in the animation.  The MediaTracker avoids this by requiring that an image be fully loaded before allowing the program to continue.
 

 
   WEBBITS Home    Back to Webbits First Java Page
 
Copyright © 1997 Margaret Brown