Source of MarsIcon.java


  1: import java.awt.*;
  2: import java.awt.geom.*;
  3: import javax.swing.*;

  5: /**
  6:    An icon that has the shape of the planet Mars.
  7: */
  8: public class MarsIcon implements Icon
  9: {
 10:    /**
 11:       Constructs a Mars icon of a given size.
 12:       @param aSize the size of the icon
 13:    */
 14:    public MarsIcon(int aSize)
 15:    {
 16:       size = aSize;
 17:    }

 19:    public int getIconWidth()
 20:    {
 21:       return size;
 22:    }

 24:    public int getIconHeight()
 25:    {
 26:       return size;
 27:    }

 29:    public void paintIcon(Component c, Graphics g, int x, int y)
 30:    {
 31:       Graphics2D g2 = (Graphics2D) g;
 32:       Ellipse2D.Double planet = new Ellipse2D.Double(x, y,
 33:             size, size);
 34:       g2.setColor(Color.RED);
 35:       g2.fill(planet);
 36:    }

 38:    private int size;
 39: }