import java.awt.*; import java.applet.*; /** * A simple circle class. * * @author Samuel A. Rebelsky * @version 1.1 of February 1999 */ public class Circle { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The current color of the circle. */ protected Color color; /** The current diameter of the circle. */ protected int diameter; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Create a new circle with specified diameter and color. */ public Circle(int diameter, Color color) { this.diameter = diameter; this.setColor(color); } // Circle(int, Color) /** * Create a new circle with specified diameter and default color. */ public Circle(int diameter) { this.diameter = diameter; this.setColor(Color.blue); // Blue is as good a default as any. } // Circle(int) // +---------+------------------------------------------------- // | Methods | // +---------+ /** * Draw this circle centered at a particular position in a * graphics thingy. To make it look more interesting, I outline * the circle in some color. */ public void draw(int x, int y, Graphics g) { g.setColor(this.color); g.fillOval( x-this.diameter/2, // Left margin y-this.diameter/2, // Top margin this.diameter, // Width this.diameter); // Height } // draw(int,int,Graphics) /** * Get the diameter of this circle. */ public int getSize() { return this.diameter; } // getSize() /** * Set the color of this circle. */ public void setColor(Color newColor) { this.color = newColor; } // setColor(Color) /** * Set the diameter of this circle. */ public void setSize(int newDiameter) { this.diameter = newDiameter; } // setSize(int) } // class Circle