public class ImageDrawDemo extends JApplet { // The init() method to initialize everything... // The start() method to start the animation... // The stop() method to stop the animation... // The ImagePanel class defining the panel displaying the animation... // Data members for the applet... } 创建一个图像
double totalAngle; // Current angular position of sprite double spriteAngle; // Rotation angle of sprite about its center ImagePanel imagePanel; // Panel to display animation
BufferedImage sprite; // Stores reference to the sprite int spriteSize = 100; // Diameter of the sprite Ellipse2D.Double circle; // A circle - part of the sprite Line2D.Double line; // A line - part of the sprite
// Colors used in sprite Color[] colors = {Color.red , Color.yellow, Color.green , Color.blue, Color.cyan, Color.pink , Color.magenta, Color.orange};
java.util.Timer timer; // Timer for the animation long interval = 50; // Time interval msec between repaints 这些成员的一般用途可以从注释中清楚地看到。下面我们要看一看开发代码时它们是怎样被使用的。