acm.graphics
Class GRect

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GRect
All Implemented Interfaces:
GFillable, GResizable, GScalable, Serializable, Cloneable
Direct Known Subclasses:
G3DRect, GRoundRect

public class GRect
extends GObject
implements GFillable, GResizable, GScalable

The GRect class is a graphical object whose appearance consists of a rectangular box.

See Also:
Serialized Form

Constructor Summary
GRect(double width, double height)
          Constructs a new rectangle with the specified width and height, positioned at the origin.
GRect(double x, double y, double width, double height)
          Constructs a new rectangle with the specified bounds.
 
Method Summary
protected  Rectangle getAWTBounds()
          Returns an AWT Rectangle that specifies the bounds of this object.
 GRectangle getBounds()
          Returns the bounding box of this object.
 Color getFillColor()
          Returns the color used to display the filled region of this object.
 double getHeight()
          Returns the height of this object as a double-precision value, which is defined to be the height of the bounding box.
 GDimension getSize()
          Returns the size of this object as a GDimension.
 double getWidth()
          Returns the width of this object as a double-precision value, which is defined to be the width of the bounding box.
 boolean isFilled()
          Returns whether this object is filled.
 void paint(Graphics g)
          Implements the paint operation for this graphical object.
 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 setBounds(double x, double y, double width, double height)
          Changes the bounds of this object to the specified values.
 void setBounds(GRectangle bounds)
          Changes the bounds of this object to the values from the specified GRectangle.
 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 setSize(double width, double height)
          Changes the size of this object to the specified width and height.
 void setSize(GDimension size)
          Changes the size of this object to the specified GDimension.
 
Methods inherited from class acm.graphics.GObject
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getLocation, getObjectColor, getParent, getX, getY, isVisible, move, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GRect

public GRect(double width,
             double height)
Constructs a new rectangle with the specified width and height, positioned at the origin.

Parameters:
width - The width of the rectangle in pixels
height - The height of the rectangle in pixels

GRect

public GRect(double x,
             double y,
             double width,
             double height)
Constructs a new rectangle with the specified bounds.

Parameters:
x - The x-coordinate of the upper left corner
y - The y-coordinate of the upper left corner
width - The width of the rectangle in pixels
height - The height of the rectangle in pixels
Method Detail

getAWTBounds

protected Rectangle getAWTBounds()
Returns an AWT Rectangle that specifies the bounds of this object.

Returns:
A Rectangle that specifies the bounds of this object

getBounds

public GRectangle getBounds()
Returns the bounding box of this object.

Specified by:
getBounds in class GObject
Returns:
The bounding box for this object

getFillColor

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.

Specified by:
getFillColor in interface GFillable
Returns:
The color used to display the filled region of this object

getHeight

public double getHeight()
Returns the height of this object as a double-precision value, which is defined to be the height of the bounding box.

Overrides:
getHeight in class GObject
Returns:
The height of this object on the screen

getSize

public GDimension getSize()
Returns the size of this object as a GDimension.

Overrides:
getSize in class GObject
Returns:
The size of this object

getWidth

public double getWidth()
Returns the width of this object as a double-precision value, which is defined to be the width of the bounding box.

Overrides:
getWidth in class GObject
Returns:
The width of this object on the screen

isFilled

public boolean isFilled()
Returns whether this object is filled.

Specified by:
isFilled in interface GFillable
Returns:
The color used to display the object

paint

public void paint(Graphics g)
Implements the paint operation for this graphical object. This method is not called directly by clients.

Specified by:
paint in class GObject
Parameters:
g - The graphics context into which the painting is done

scale

public final void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.

Specified by:
scale in interface GScalable
Parameters:
sf - The factor used to scale all coordinates in both dimensions

scale

public void scale(double sx,
                  double sy)
Scales the object on the screen by the scale factors sx and sy.

Specified by:
scale in interface GScalable
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

setBounds

public void setBounds(double x,
                      double y,
                      double width,
                      double height)
Changes the bounds of this object to the specified values.

Specified by:
setBounds in interface GResizable
Parameters:
x - The new x-coordinate for the object
y - The new y-coordinate for the object
width - The new width of the object
height - The new height of the object

setBounds

public final void setBounds(GRectangle bounds)
Changes the bounds of this object to the values from the specified GRectangle.

Specified by:
setBounds in interface GResizable
Parameters:
bounds - A GRectangle specifying the new bounds

setFillColor

public void setFillColor(Color color)
Sets the color used to display the filled region of this object.

Specified by:
setFillColor in interface GFillable
Parameters:
color - The color used to display the filled region of this object

setFilled

public void setFilled(boolean fill)
Sets whether this object is filled.

Specified by:
setFilled in interface GFillable
Parameters:
fill - true if the object should be filled, false for an outline

setSize

public void setSize(double width,
                    double height)
Changes the size of this object to the specified width and height.

Specified by:
setSize in interface GResizable
Parameters:
width - The new width of the object
height - The new height of the object

setSize

public final void setSize(GDimension size)
Changes the size of this object to the specified GDimension.

Specified by:
setSize in interface GResizable
Parameters:
size - A GDimension object specifying the size