import Java.util.*; import javax.microedition.lcdui.*; // 定义了一个动画,该动画其实只是一系列相同大小的图片 // 轮流显示,然后模拟出的动画 public class AnimatedImage extends TimerTask {; private Canvas canvas; private Image[] images; private int[][] clipList; private int current; private int x; private int y; private int w; private int h; // ConstrUCt an animation with no canvas. public AnimatedImage( Image[] images ){; this( null, images, null ); }; // Construct an animation with a null clip list. public AnimatedImage( Canvas canvas, Image[] images ){; this( canvas, images, null ); }; // Construct an animation. The canvas can be null, // but if not null then a repaint will be triggered // on it each time the image changes due to a timer // event. If a clip list is specified, the image is // drawn multiple times, each time with a different // clip rectangle, to simulate transparent parts. public AnimatedImage( Canvas canvas, Image[] images, int[][] clipList ){; this.canvas = canvas; this.images = images; this.clipList = clipList; if( images != null && clipList != null ){; if( clipList.length < images.length ){; throw new IllegalArgumentException(); }; }; if( images != null && images.length > 0 ){; w = images[0].getWidth(); h = images[0].getHeight(); }; }; // Move to the next frame, wrapping if necessary. public void advance( boolean repaint ){; if( ++current >= images.length ){; current = 0; }; if( repaint && canvas != null && canvas.isShown() ){; canvas.repaint( x, y, w, h ); canvas.serviceRepaints(); }; }; // Draw the current image in the animation. If // no clip list, just a simple copy, otherwise // set the clipping rectangle accordingly and // draw the image multiple times. public void draw( Graphics g ){;