001package horstmann.ch04_animation;
002import java.awt.Component;
003import java.awt.Graphics;
004import java.awt.Graphics2D;
005
006import javax.swing.Icon;
007
008/**
009   An icon that contains a moveable shape.
010 */
011public class ShapeIcon implements Icon
012{
013        public ShapeIcon(MoveableShape shape,
014                        int width, int height)
015        {
016                this.shape = shape;
017                this.width = width;
018                this.height = height;
019        }
020
021        public int getIconWidth()
022        {
023                return width;
024        }
025
026        public int getIconHeight()
027        {
028                return height;
029        }
030
031        public void paintIcon(Component c, Graphics g, int x, int y)
032        {
033                Graphics2D g2 = (Graphics2D) g;
034                shape.draw(g2);
035        }
036
037        private int width;
038        private int height;
039        private MoveableShape shape;
040}
041
042