/* Circle.java
*
* Bruce M. Bolden
* February 8, 1998
* http://www.cs.uidaho.edu/~bruceb/
*/
import java.awt.Color;
import java.awt.Graphics;
/** Parent class for all circular objects. */
final public class Circle extends GObject
{
private int radius;
private static final int DEFAULT_RADIUS = 10;
public Circle() {
setX( 0 ); // default position (0, 0)
setY( 0 );
setColor( Color.black );
this.radius = DEFAULT_RADIUS;
}
public Circle(int x, int y, Color c) {
this( x, y, c, DEFAULT_RADIUS );
}
public Circle(int x, int y, Color c, int r) {
setX( x );
setY( y );
setColor( c );
this.radius = r;
}
/** calculates the area of a rectangular object */
public double area() {
return Math.PI * radius * radius;
}
/** writes the area to standard output stream
* Note the use of the method area() */
public void showArea() {
System.out.println( " " + area() );
}
/** writes the color to standard output stream
* Note the use of toString(). */
public void showColor() {
System.out.println( " " + c.toString() );
}
/** draw the circle */
public void draw( Graphics g ) {
g.setColor( getColor() );
g.drawOval( x, y, radius, radius );
}
}