// Circle.java
import java.awt.Graphics;
/**
* Class of objects representing circles that can be
* drawn and their area calculated.
*
* @author D. Nixon
*/
public class Circle extends ShapeOutline {
/** Count of Circle objects instantiated so far */
private static int objectCount = 0;
/**
* Creates a Circle with the specified diameter.
*
* @param w integer specifying width in pixels
* @exception NegativeSizeException if
* <code>w</code> < 0.
*/
public Circle( int w )
{
super(w);
// So that getCount will know how many
// Circle objects have been created:
objectCount++;
} // constructor Circle(int)
/**
* Draws this Circle at a specified location
* using a specified Graphics context
*
* @param g the Graphics context
* @param pixelsFromLeft integer distance from left
* side of display area to left side of
* drawing of this Circle
* @param pixelsFromTop integer distance from top
* of display area to top of drawing of this
* Circle
*/
public void draw( Graphics g,
int pixelsFromLeft,
int pixelsFromTop )
{
g.drawOval(pixelsFromLeft, pixelsFromTop,
getWidth(), getWidth());
} // method draw(Graphics, int, int)
/**
* Determines approximate number of pixels
* enclosed by this Circle
*
* @return floating-point area of this Circle,
* in pixels
*/
public float getArea()
{
return(3.14159f * getWidth() * getWidth() / 4);
} // method getArea
/**
* Gets a count of Circle objects instantiated so far.
*
* @return integer number of Circle objects
*/
public static int getCount()
{
return objectCount;
} // method getCount
} // class Circle