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
// Clear image
with transparent alpha by drawing a
rectangle g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,
0.0f)); Rectangle2D.Double rect = new
Rectangle2D.Double(0,0,spriteSize,spriteSize);
g2D.fill(rect);
BufferedImage
createSprite(int spriteSize) { // Create image with RGB and alpha
channel BufferedImage sprite = new BufferedImage(spriteSize,
spriteSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D =
sprite.createGraphics(); // Context for buffered image
// Set best alpha
interpolation
quality g2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
// Clear image
with transparent alpha by drawing a
rectangle g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,
0.0f)); Rectangle2D.Double rect = new
Rectangle2D.Double(0,0,spriteSize,spriteSize); g2D.fill(rect);