acm.graphics
Class GObject

java.lang.Object
  |
  +--acm.graphics.GObject
Direct Known Subclasses:
GArc, GCompound, GImage, GLine, GOval, GPen, GPolygon, GRect, GString

public abstract class GObject implements Cloneable

This class is the common superclass of all graphical objects that can be displayed on a GCanvas. Because it is an abstract class, you are not allowed to construct an object whose class is GObject directly. What you do instead is construct one of the concrete subclasses like GRect or GLine. The purpose of this class definition is to define methods that apply to all graphical objects regardless of their specific class.


Method Summary
void addMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object.
void addMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object.
boolean contains(double x, double y)
Checks to see whether a point is inside the object.
boolean contains(Point pt)
Checks to see whether a point is inside the object, where the point is specified as a Point, as defined in java.awt.
Rectangle getBounds()
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.
Color getColor()
Returns the color used to display this object.
Component getComponent()
Returns the component in which this object is installed, or null if none exists.
Color getFillColor()
Returns the color used to display the filled region of this object.
double getHeight()
Returns the height of this object.
Point getLocation()
Returns the nearest Point corresponding to the location of this object.
GContainer getParent()
Returns the parent of this object, which is the canvas or compound object in which it is enclosed.
Dimension getSize()
Returns the size of this object as a Dimension.
double getWidth()
Returns the width of this object.
double getX()
Returns the x-coordinate of the object.
double getY()
Returns the y-coordinate of the object.
boolean isFilled()
Returns whether this object is filled.
boolean isVisible()
Checks to see whether this object is visible.
void moveToBack()
Moves this object to the back of the display in stacking order.
void moveToFront()
Moves this object to the front of the display in stacking order.
abstract  void paint(Graphics g)
All subclasses of GObject must define a paint method which allows the object to draw itself on the Graphics context passed in as the parameter g.
void removeMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object.
void removeMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from 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 setColor(Color c)
Sets the color used to display this object.
void setFillColor(Color c)
Sets the color used to display the filled region of this object.
void setFilled(boolean fill)
Sets whether this object is filled.
void setLocation(double x, double y)
Sets the location of this object to the point (x, y).
void setLocation(Point pt)
Sets the location of this object to the specified point, specified using the standard Point class from java.awt.
void setSize(Dimension size)
Changes the size of this object to the specified Dimension object as defined in java.awt.
void setSize(double width, double height)
Changes the size of this object to the specified width and height.
void setVisible(boolean visible)
Sets whether this object is visible.
void translate(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
 

Method Detail

public void addMouseListener(MouseListener listener)

Adds a mouse listener to this graphical object.
 
Usage: gobj.addMouseListener(listener);
Parameter: 
listener  Any object that implements the MouseListener interface
 

public void addMouseMotionListener(MouseMotionListener listener)

Adds a mouse motion listener to this graphical object.
 
Usage: gobj.addMouseMotionListener(listener);
Parameter: 
listener  Any object that implements the MouseMotionListener interface
 

public boolean contains(double x, double y)

Checks to see whether a point is inside the object. By default, this method simply checks to see if the point is inside the bounding box. Most subclasses will need to override this to check whether the point is contained in the shape.
 
Usage: if (gobj.contains(x, y)) . . .
Parameters: 
x  The x-coordinate of the point being tested
y  The y-coordinate of the point being tested
Returns: true if the point (xy) is inside the object, and false otherwise
 

public final boolean contains(Point pt)

Checks to see whether a point is inside the object, where the point is specified as a Point, as defined in java.awt.
 
Usage: if (gobj.contains(pt)) . . .
Parameter: 
pt  The point being tested
Returns: true if the point is inside the object, and false otherwise
 

public Rectangle getBounds()

Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure. The coordinates of this rectangle do not necessarily match the location returned by getLocation. Given a GString object, for example, getLocation returns the coordinates of the point on the baseline at which the string begins; getBounds, by contrast, returns a rectangle that covers the entire window area occupied by the string.
 
Usage: Rectangle bounds = gobj.getBounds();
Returns: The bounding box for this object
 

public Color getColor()

Returns the color used to display this object.
 
Usage: Color color = gobj.getColor();
Returns: The color used to display this object
 

public Component getComponent()

Returns the component in which this object is installed, or null if none exists.

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
 

public double getHeight()

Returns the height of this object. Note that this is the height as established by the setSize method and may not correspond to the apparent height of the figure. To get the actual bounds of the figure, use getBounds.
 
Usage: double height = gobj.getHeight();
Returns: The height of this object on the screen
 

public Point getLocation()

Returns the nearest Point corresponding to the location of this object.
 
Usage: Point pt = gobj.getLocation();
Returns: The nearest Point corresponding to the location of this object
 

public GContainer getParent()

Returns the parent of this object, which is the canvas or compound object in which it is enclosed.
 
Usage: GContainer parent = gobj.getParent();
Returns: The parent of this object
 

public Dimension getSize()

Returns the size of this object as a Dimension. Note that this is the size as established by the setSize method and may not correspond to the apparent size of the figure. To get the actual bounds of the figure, use getBounds.
 
Usage: Dimension size = gobj.getSize();
Returns: The size of this object
 

public double getWidth()

Returns the width of this object. Note that this is the width as established by the setSize method and may not correspond to the apparent width of the figure. To get the actual bounds of the figure, use getBounds.
 
Usage: double width = gobj.getWidth();
Returns: The width of this object on the screen
 

public double getX()

Returns the x-coordinate of the object.
 
Usage: double x = gobj.getX();
Returns: The x-coordinate of the object
 

public double getY()

Returns the y-coordinate of the object.
 
Usage: double y = gobj.getY();
Returns: The y-coordinate of the object
 

public boolean isFilled()

Returns whether this object is filled.
 
Usage: if (gobj.isFilled()) . . .
Returns: The color used to display the object
 

public boolean isVisible()

Checks to see whether this object is visible.
 
Usage: if (gobj.isVisible()) . . .
Returns: true if the object is visible, otherwise false
 

public void moveToBack()

Moves this object to the back of the display in stacking order. By moving it to the back, this object will appear to be behind the other graphical objects on the display and may be obscured by other objects in front.
 
Usage: gobj.moveToBack();
 

public void moveToFront()

Moves this object to the front of the display in stacking order. By moving it to the front, this object will appear to be on top of the other graphical objects on the display and may hide any objects that are further back.
 
Usage: gobj.moveToFront();
 

public abstract void paint(Graphics g)

All subclasses of GObject must define a paint method which allows the object to draw itself on the Graphics context passed in as the parameter g.
 
Usage: gobj.paint(g);
Parameter: 
g  The graphics context into which the painting is done
 

public void removeMouseListener(MouseListener listener)

Removes a mouse listener from this graphical object.
 
Usage: gobj.removeMouseListener(listener);
Parameter: 
listener  The listener object to remove
 

public void removeMouseMotionListener(MouseMotionListener listener)

Removes a mouse motion listener from this graphical object.
 
Usage: gobj.removeMouseMotionListener(listener);
Parameter: 
listener  The listener object to remove
 

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
 

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
 

public void setColor(Color c)

Sets the color used to display this object.
 
Usage: gobj.setColor(color);
Parameter: 
color  The color used to display this object
 

public void setFillColor(Color c)

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
 

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
 

public void setLocation(double x, double y)

Sets the location of this object to the point (x, y).
 
Usage: gobj.setLocation(x, y);
Parameters: 
x  The new x-coordinate for the object
y  The new y-coordinate for the object
 

public final void setLocation(Point pt)

Sets the location of this object to the specified point, specified using the standard Point class from java.awt.

public final void setSize(Dimension size)

Changes the size of this object to the specified Dimension object as defined in java.awt.

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
 

public void setVisible(boolean visible)

Sets whether this object is visible.
 
Usage: gobj.setVisible(visible);
Parameter: 
visible  true to make the object visible, false to hide it
 

public void translate(double dx, double dy)

Moves the object on the screen using the displacements dx and dy.
 
Usage: gobj.translate(dx, dy);
Parameters: 
dx  The distance to move the object in the x direction (positive is rightward)
dy  The distance to move the object in the y direction (positive is downward)