001package horstmann.ch04_icon2;
002import java.awt.Color;
003import java.awt.Component;
004import java.awt.Graphics;
005import java.awt.Graphics2D;
006import java.awt.geom.Ellipse2D;
007
008import javax.swing.Icon;
009
010/**
011   An icon that has the shape of the planet Mars.
012 */
013public class MarsIcon implements Icon
014{
015        /**
016      Constructs a Mars icon of a given size.
017      @param aSize the size of the icon
018         */
019        public MarsIcon(int aSize)
020        {
021                size = aSize;
022        }
023
024        public int getIconWidth()
025        {
026                return size;
027        }
028
029        public int getIconHeight()
030        {
031                return size;
032        }
033
034        public void paintIcon(Component c, Graphics g, int x, int y)
035        {
036                Graphics2D g2 = (Graphics2D) g;
037                Ellipse2D.Double planet = new Ellipse2D.Double(x, y,
038                                size, size);
039                g2.setColor(Color.RED);
040                g2.fill(planet);
041        }
042
043        private int size;
044}