edu.neu.ccs.gui
Class Circle

java.lang.Object
  |
  +--java.awt.geom.RectangularShape
        |
        +--java.awt.geom.Ellipse2D
              |
              +--java.awt.geom.Ellipse2D.Double
                    |
                    +--edu.neu.ccs.gui.Oval
                          |
                          +--edu.neu.ccs.gui.Circle
All Implemented Interfaces:
Cloneable, Shape

public class Circle
extends Oval

Class Circle extends Oval but requires that its location be specifed by its center and its size be specified by its radius. The diameter of the circle is twice the radius and is the value returned by either getWidth or getHeight.

The design of this class makes it similar to the class Square.

Inherited methods that would permit the caller to make the width and height have different values are overridden to do nothing.

Since:
2.4.0

Field Summary
 
Fields inherited from class java.awt.geom.Ellipse2D.Double
height, width, x, y
 
Constructor Summary
Circle()
          Constructs a new Circle initialized to center (0, 0) and radius 0.
Circle(Circle circle)
          Constructs and initializes a Circle from the specified Circle object.
Circle(double r)
          Constructs a new Circle initialized to center (0, 0) and with the given radius r.
Circle(double x, double y, double r)
          Constructs and initializes a Circle from the specified double coordinates.
 
Method Summary
 double getRadius()
          Returns the radius.
 void setCircle(Circle circle)
          Uses the data from the given circle to set the parameters of this circle.
 void setXYR(double x, double y, double r)
          Sets the parameters of the Circle with error checking.
 void setXYWH(double x, double y, double w, double h)
          Overrides the inherited method to do nothing since a circle cannot have a distinct width and height.
 String toString()
          Returns a String representation of the data in this Circle.
 
Methods inherited from class edu.neu.ccs.gui.Oval
setFrame, setFrame, setFrame, setOval, setX1Y1X2Y2, setXYRS
 
Methods inherited from class java.awt.geom.Ellipse2D.Double
getBounds2D, getHeight, getWidth, getX, getY, isEmpty
 
Methods inherited from class java.awt.geom.Ellipse2D
contains, contains, getPathIterator, intersects
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, getPathIterator, intersects, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Circle

public Circle()
Constructs a new Circle initialized to center (0, 0) and radius 0.


Circle

public Circle(double x,
              double y,
              double r)
Constructs and initializes a Circle from the specified double coordinates. Calls setXYR.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed radius

Circle

public Circle(double r)

Constructs a new Circle initialized to center (0, 0) and with the given radius r. Calls setXYR

Parameters:
r - the proposed radius

Circle

public Circle(Circle circle)

Constructs and initializes a Circle from the specified Circle object. Calls setXYR.

Initializes to center (0, 0) and radius 0 if the given circle is null.

Parameters:
circle - the Circle object to copy
Method Detail

setXYR

public void setXYR(double x,
                   double y,
                   double r)

Sets the parameters of the Circle with error checking.

If the radius r is negative, then r is replaced by its absolute value before further computation.

The circle is then set up as an ellipse with corner location (x-r, y-r) and common width and height equal to 2*r.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed radius

setCircle

public void setCircle(Circle circle)

Uses the data from the given circle to set the parameters of this circle.

Does nothing if the given circle is null.

Parameters:
circle - the Circle object to copy

getRadius

public double getRadius()
Returns the radius.


setXYWH

public void setXYWH(double x,
                    double y,
                    double w,
                    double h)

Overrides the inherited method to do nothing since a circle cannot have a distinct width and height.

The fact that this method does nothing implies that the following methods inherited from Oval and other base classes also do nothing:

Overrides:
setXYWH in class Oval
Parameters:
x - the proposed top-left x-coordinate of the frame
y - the proposed top-left y-coordinate of the frame
w - the proposed width of the frame
h - the proposed height of the frame

toString

public String toString()

Returns a String representation of the data in this Circle.

The format is similar to that used by Java but simpler:

Circle[x=...,y=...,r=...]

where (x,y) is the center and r is the radius.

Overrides:
toString in class Oval