acm.graphics
Class GArc

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GArc

public class GArc
extends GObject
implements GFillable, GScalable

The GArc class is a graphical object whose appearance consists of an arc. If unfilled, the arc is simply a portion of the circumference of an ellipse; if filled, the arc is a pie-shaped wedge connected to the center of the figure.


Field Summary
double ARC_TOLERANCE
This constant defines how close (measured in pixel units) a point has to be to an arc before that point is considered to be "contained" within the arc.
 
Constructor Summary
GArc(double width, double height, double start, double sweep)
Creates a new GArc object consisting of an elliptical arc located at the point (0, 0).
GArc(double x, double y, double width, double height, double start, double sweep)
Creates a new GArc object consisting of an elliptical arc inscribed in a rectangle located at the point (xy) with the specified width and height.
 
Method Summary
 boolean contains(double x, double y)
Checks to see whether a point is inside the object.
 GRectangle getBounds()
Returns the bounding box of the arc.
 GPoint getEndPoint()
Returns the point at which the arc ends.
 Color getFillColor()
Returns the color used to display the filled region of this object.
 GRectangle getFrameRectangle()
Returns the bounds of the GRectangle in which this arc is inscribed.
 double getStartAngle()
Returns the starting angle for this GArc object.
 GPoint getStartPoint()
Returns the point at which the arc starts.
 double getSweepAngle()
Returns the sweep angle for this GArc object.
 boolean isFilled()
Returns whether this object is filled.
 void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.
 void scale(double sx, double sy)
Scales the object on the screen by the scale factors sx and sy.
 void setFillColor(Color color)
Sets the color used to display the filled region of this object.
 void setFilled(boolean fill)
Sets whether this object is filled.
 void setFrameRectangle(double x, double y, double width, double height)
Changes the arc bounds to the specified values.
 void setFrameRectangle(GRectangle bounds)
Changes the arc bounds to the values from the specified GRectangle.
 void setStartAngle(double start)
Sets the starting angle for this GArc object.
 void setSweepAngle(double sweep)
Sets the sweep angle for this GArc object.
 
Inherited Method Summary
voidaddMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object.
voidaddMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object.
booleancontains(GPoint pt)
Checks to see whether a point is inside the object.
ColorgetColor()
Returns the color used to display this object.
doublegetHeight()
Returns the height of this object, which is defined to be the height of the bounding box.
GPointgetLocation()
Returns the location of this object as a GPoint.
GDimensiongetSize()
Returns the size of the bounding box for this object.
doublegetWidth()
Returns the width of this object, which is defined to be the width of the bounding box.
doublegetX()
Returns the x-coordinate of the object.
doublegetY()
Returns the y-coordinate of the object.
booleanisVisible()
Checks to see whether this object is visible.
voidmove(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
voidmovePolar(double r, double theta)
Moves the object using displacements given in polar coordinates.
voidremoveMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object.
voidremoveMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object.
voidsendBackward()
Moves this object one step toward the back in the z dimension.
voidsendForward()
Moves this object one step toward the front in the z dimension.
voidsendToBack()
Moves this object to the back of the display in the z dimension.
voidsendToFront()
Moves this object to the front of the display in the z dimension.
voidsetColor(Color color)
Sets the color used to display this object.
voidsetLocation(GPoint pt)
Sets the location of this object to the specified point.
voidsetLocation(double x, double y)
Sets the location of this object to the point (x, y).
voidsetVisible(boolean visible)
Sets whether this object is visible.
 

Field Detail

public static final double ARC_TOLERANCE

This constant defines how close (measured in pixel units) a point has to be to an arc before that point is considered to be "contained" within the arc.

See Also:
Constant Field Values
Constructor Detail

public GArc(double width, double height, double start, double sweep)

Creates a new GArc object consisting of an elliptical arc located at the point (0, 0). For complete descriptions of the other parameters, see the entry for the GArc constructor that includes explicit x and y parameters.

 
Usage: GArc garc = new GArc(width, height, start, sweep); 
Parameters: 
width  The width of the rectangle in which the arc is inscribed
height  The height of the rectangle in which the arc is inscribed
start  The angle at which the arc begins measured in degrees counterclockwise from the +x axis
sweep  The extent of the arc, measured in degrees counterclockwise
 


public GArc(double x, double y, double width, double height, double start, double sweep)

Creates a new GArc object consisting of an elliptical arc inscribed in a rectangle located at the point (xy) with the specified width and height. The start parameter indicates the angle at which the arc begins and is measured in degrees counterclockwise from the +x axis. Thus, a start angle of 0 indicates an arc that begins along the line running eastward from the center (the 3:00 o’clock position), a start angle of 135 begins along the line running northwest, and a start angle of -90 begins along the line running south (the 6:00 o’clock position). The sweep parameter indicates the extent of the arc and is also measured in degrees counterclockwise. A sweep angle of 90 defines a quarter circle extending counterclockwise from the start angle, and a sweep angle of -180 defines a semicircle extending clockwise.

 
Usage: GArc garc = new GArc(x, y, width, height, start, sweep); 
Parameters: 
 The x-coordinate for the rectangle in which the arc is inscribed
 The y-coordinate for the rectangle in which the arc is inscribed
width  The width of the rectangle in which the arc is inscribed
height  The height of the rectangle in which the arc is inscribed
start  The angle at which the arc begins measured in degrees counterclockwise from the +x axis
sweep  The extent of the arc, measured in degrees counterclockwise
 

Method Detail

public boolean contains(double x, double y)

Checks to see whether a point is inside the object. For the GArc class, containment depends on whether the arc is filled. Filled arcs are a wedge in which containment can be defined in a natural way; unfilled arcs are essentially lines, which means that containment is defined to mean that the point is within ARC_TOLERANCE pixels of the arc.

 
Usage: if (garc.contains(x, y)) . . . 
Parameters: 
 The x-coordinate of the point being tested
 The y-coordinate of the point being tested
Returns: true if the point (xy) is inside
 


public GRectangle getBounds()

Returns the bounding box of the arc. Note that this method returns the bounds of the visible portion of the arc and will therefore not contain the same values as specified in setFrameRectangle. To obtain the bounds used to describe the Java arc, use getFrameRectangle.

 
Usage: GRectangle bounds = garc.getBounds(); 
Returns: The bounding box of this object
 

Specified by:
getBounds in class GObject

public GPoint getEndPoint()

Returns the point at which the arc ends.

 
Usage: GPoint pt = garc.getEndPoint(); 
Returns: The point at which the arc ends
 


public Color getFillColor()

Returns the color used to display the filled region of this object. If none has been set, getFillColor returns the color of the object.

 
Usage: Color color = garc.getFillColor(); 
Returns: The color used to display the filled region of this object
 

Specified by:
getFillColor in interface GFillable

public GRectangle getFrameRectangle()

Returns the bounds of the GRectangle in which this arc is inscribed. Note that this is usually different from the bounding box returned by getBounds, which returns the bounding box in which the displayed portion of the arc is contained.

 
Usage: GRectangle bounds = garc.getFrameRectangle(); 
Returns: The GRectangle in which this arc is inscribed
 


public double getStartAngle()

Returns the starting angle for this GArc object.

 
Usage: double start = garc.getStartAngle(); 
Returns: The starting angle for this arc
 


public GPoint getStartPoint()

Returns the point at which the arc starts.

 
Usage: GPoint pt = garc.getStartPoint(); 
Returns: The point at which the arc starts
 


public double getSweepAngle()

Returns the sweep angle for this GArc object.

 
Usage: double sweep = garc.getSweepAngle(); 
Returns: The sweep angle for this arc
 


public boolean isFilled()

Returns whether this object is filled.

 
Usage: if (garc.isFilled()) . . . 
Returns: The color used to display the object
 

Specified by:
isFilled in interface GFillable

public final void scale(double sf)

Scales the object on the screen by the scale factor sf, which applies in both dimensions.

 
Usage: gobj.scale(sf); 
Parameter: 
sf  The factor used to scale all coordinates in both dimensions
 

Specified by:
scale in interface GScalable

public void scale(double sx, double sy)

Scales the object on the screen by the scale factors sx and sy.

 
Usage: gobj.scale(sx, sy); 
Parameters: 
sx  The factor used to scale all coordinates in the x direction
sy  The factor used to scale all coordinates in the y direction
 

Specified by:
scale in interface GScalable

public void setFillColor(Color color)

Sets the color used to display the filled region of this object.

 
Usage: garc.setFillColor(color); 
Parameter: 
color  The color used to display the filled region of this object
 

Specified by:
setFillColor in interface GFillable

public void setFilled(boolean fill)

Sets whether this object is filled.

 
Usage: garc.setFilled(fill); 
Parameter: 
fill  true if the object should be filled, false for an outline
 

Specified by:
setFilled in interface GFillable

public void setFrameRectangle(double x, double y, double width, double height)

Changes the arc bounds to the specified values.

 
Usage: garc.setBounds(x, y, width, height); 
Parameters: 
 The x-coordinate for the rectangle in which the arc is inscribed
 The y-coordinate for the rectangle in which the arc is inscribed
width  The width of the rectangle in which the arc is inscribed
height  The height of the rectangle in which the arc is inscribed
 


public final void setFrameRectangle(GRectangle bounds)

Changes the arc bounds to the values from the specified GRectangle.

 
Usage: garc.setFrameRectangle(bounds); 
Parameter: 
bounds  A GRectangle specifying the new arc bounds
 


public void setStartAngle(double start)

Sets the starting angle for this GArc object.

 
Usage: garc.setStartAngle(start); 
Parameter: 
start  The new starting angle
 


public void setSweepAngle(double sweep)

Sets the sweep angle for this GArc object.

 
Usage: garc.setSweepAngle(sweep); 
Parameter: 
sweep  The new sweep angle