Adding Animation

As you develop your user interfaces—particularly user interfaces for applets—you might find a need for animation. The previous section explored drawImage(); it is the graphical analog of drawString() that you've been using for a while. Listing 38.7 illustrates an animation technique you might consider using.

Code Listing 38.7. Animation1.java—This Applet Loads and Displays a Series of Images in Rapid Succession
 import java.awt.*; import java.applet.Applet; public class Animation1 extends Applet implements Runnable { int fFrame = -1; int fDelay; Thread fThread; Image[] fEarth; public void init() { fEarth = new Image[30]; String theString; int theFramesPerSecond = 10; //load in the images for (int i=1; i<=30; i++) { System.err.println("Starting ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.