acm.graphics
Class GRect

java.lang.Object
  extended by acm.graphics.GObject
      extended by acm.graphics.GRect
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.


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
 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 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.
 
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.
booleancontains(double x, double y)
Checks to see whether a point is inside the object.
ColorgetColor()
Returns the color used to display this object.
GPointgetLocation()
Returns the location of this object as a GPoint.
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.
 

Constructor Detail

public GRect(double width, double height)

Constructs a new rectangle with the specified width and height, positioned at the origin.

 
Usage: GRect grect = new GRect(width, height); 
Parameters: 
width  The width of the rectangle in pixels
height  The height of the rectangle in pixels
 


public GRect(double x, double y, double width, double height)

Constructs a new rectangle with the specified bounds.

 
Usage: GRect grect = new GRect(x, y, width, height); 
Parameters: 
 The x-coordinate of the upper left corner
 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

public GRectangle getBounds()

Returns the bounding box of this object.

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

Specified by:
getBounds in class GObject

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 = gobj.getFillColor(); 
Returns: The color used to display the filled region of this object
 

Specified by:
getFillColor in interface GFillable

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.

 
Usage: double height = gobj.getHeight(); 
Returns: The height of this object on the screen
 


public GDimension getSize()

Returns the size of this object as a GDimension.

 
Usage: GDimension size = gobj.getSize(); 
Returns: The size of this object
 


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.

 
Usage: double width = gobj.getWidth(); 
Returns: The width of this object on the screen
 


public boolean isFilled()

Returns whether this object is filled.

 
Usage: if (gobj.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 setBounds(double x, double y, double width, double height)

Changes the bounds of this object to the specified values.

 
Usage: gobj.setBounds(x, y, width, height); 
Parameters: 
 The new x-coordinate for the object
 The new y-coordinate for the object
width  The new width of the object
height  The new height of the object
 

Specified by:
setBounds in interface GResizable

public final void setBounds(GRectangle bounds)

Changes the bounds of this object to the values from the specified GRectangle.

 
Usage: gobj.setBounds(bounds); 
Parameter: 
bounds  A GRectangle specifying the new bounds
 

Specified by:
setBounds in interface GResizable

public void setFillColor(Color color)

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

 
Usage: gobj.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: gobj.setFilled(fill); 
Parameter: 
fill  true if the object should be filled, false for an outline
 

Specified by:
setFilled in interface GFillable

public void setSize(double width, double height)

Changes the size of this object to the specified width and height.

 
Usage: gobj.setSize(width, height); 
Parameters: 
width  The new width of the object
height  The new height of the object
 

Specified by:
setSize in interface GResizable