import java.awt.*; import java.lang.String; import java.applet.Applet; import java.net.URL; import java.lang.Integer; /** A class for holding a sequence of Images. Used by AnimatedSprite for a series of images shown one after the other. Used by PointSprite to hold the various rotations of an image, starting with due right. */ public class Sequence extends Object { Image frame[]; MediaTracker tracker; int width, height; // not currently used /** Loads images and builds Sequence object. Uses MediaTracker to force complete image loading. Uses Applet.showStatus() to inform user of progress in loading images. @param name A stub for the images' filenames, in the current document base. Images start at 0 and are given a ".gif" suffix. So, name "graphics/ball" looks in a "graphics" folder in the current document base for files named "ball0.gif", "ball1.gif", etc. @param num Number of images to load into the sequence @param applet Calling applet. Needed to inform user of image-loading progress */ public Sequence (String name, int num, Applet applet) { int counter; URL documentBase = applet.getDocumentBase(); tracker = new MediaTracker(applet); frame = new Image [num]; for (counter = 0; counter < num; counter++) { frame[counter] = applet.getImage (documentBase, name + Integer.toString (counter) + ".gif"); tracker.addImage (frame[counter], 0); } /* for */ applet.showStatus ("Getting sprite images: " + name); try { tracker.waitForID(0); } catch (InterruptedException e) { } } /* full constructor */ /** Returns the image at the specified index of this Sequence. @param index The index of the image to return @return The image at the specified index. If index is negative or greater than the length of the sequence, returns null. */ public Image imageAt (int index) { if ((index >=0) | (index <= frame.length)) { return frame[index]; } else { return null; } } // imageAt /** Returns length of the Sequence, ie, how many images are in it @return Length of the Sequence */ public int getLength () { return frame.length; } }