import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** An improved variation of the Circle class that
 *  uses Java 1.1 lightweight components instead
 *  of Canvas.
 * @see Circle
 */

public class BetterCircle extends Component {
  private Dimension preferredDimension;
  
  public BetterCircle(Color foreground, int radius) {
    setForeground(foreground);
    preferredDimension =
      new Dimension(2*radius, 2*radius);
    setSize(preferredDimension);
  }

  public void paint(Graphics g) {
    g.setColor(getForeground());
    g.fillOval(0, 0, getSize().width, getSize().height);
  }

  public void setCenter(int x, int y) {
    setLocation(x - getSize().width/2,
                y - getSize().height/2);
  }

  /** Report the original size as the preferred size.
   *  That way, the BetterCircle doesn't get
   *  shrunk by layout managers.
   */
  
  public Dimension getPreferredSize() {
    return(preferredDimension);
  }

  /** Report same thing for minimum size as
   *  preferred size.
   */
  
  public Dimension getMinimumSize() {
    return(preferredDimension);
  }
}
