SE450: Interface Types [7/41] Previous pageContentsNext page

file:horstmann/ch04_icon2/MarsIcon.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package horstmann.ch04_icon2;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

import javax.swing.Icon;

/**
   An icon that has the shape of the planet Mars.
 */
public class MarsIcon implements Icon
{
  /**
      Constructs a Mars icon of a given size.
      @param aSize the size of the icon
   */
  public MarsIcon(int aSize)
  {
    size = aSize;
  }

  public int getIconWidth()
  {
    return size;
  }

  public int getIconHeight()
  {
    return size;
  }

  public void paintIcon(Component c, Graphics g, int x, int y)
  {
    Graphics2D g2 = (Graphics2D) g;
    Ellipse2D.Double planet = new Ellipse2D.Double(x, y,
        size, size);
    g2.setColor(Color.RED);
    g2.fill(planet);
  }

  private int size;
}

file:horstmann/ch04_icon2/IconTester.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
package horstmann.ch04_icon2;
import javax.swing.JOptionPane;

public class IconTester
{
  public static void main(String[] args)
  {
    JOptionPane.showMessageDialog(
        null,
        "Hello, Mars!",
        "Message",
        JOptionPane.INFORMATION_MESSAGE,
        new MarsIcon(50));
    System.exit(0);
  }
}

Previous pageContentsNext page