Class GObject

This class is the common superclass of all graphical objects that can be displayed on a GWindow. 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
contains(x, y)
Checks to see whether a point is inside the object.
getBounds()
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.
getColor()
Returns the color used to display this object.
getHeight()
Returns the height of this object, which is defined to be the height of the bounding box.
getLineWidth()
Returns the width of the lines used to draw the object.
getLocation()
Returns the location of this object as a GPoint.
getSize()
Returns the size of the bounding box for this object.
getWidth()
Returns the width of this object, which is defined to be the width of the bounding box.
getX()
Returns the x-coordinate of the object.
getY()
Returns the y-coordinate of the object.
isVisible()
Checks to see whether this object is visible.
move(dx, dy)
Moves the object on the screen using the displacements dx and dy.
movePolar(r, theta)
Moves the object using displacements given in polar coordinates.
rotate(theta)
Rotates the object on the screen theta degrees around its origin.
scale(sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.
sendBackward()
Moves this object one step toward the back in the z dimension.
sendForward()
Moves this object one step toward the front in the z dimension.
sendToBack()
Moves this object to the back of the display in the z dimension.
sendToFront()
Moves this object to the front of the display in the z dimension.
setColor(color)
Sets the color used to display this object.
setLineWidth(width)
Sets the width of the lines used to draw the object.
setLocation(x, y)
Sets the location of this object to the point (x, y).
setVisible(flag)
Sets whether this object is visible.
 

Method Detail

contains(x, y)

Checks to see whether a point is contained in this object.
Usage: if gcomp.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 the object, and False otherwise
 

getBounds()

Returns the bounding rectangle for this object.
Usage: bounds = gcomp.getBounds() 
Returns: The bounding box for this object
 


getColor()

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


getHeight()

Returns the height of this object, which is defined to be the height of the bounding box.
Usage: height = gobj.getHeight() 
Returns: The height of this object on the screen
 


getLineWidth()

Returns the width of the lines used to draw the object.
Usage: width = gobj.getLineWidth() 
Returns: The line width in pixels
 


getLocation()

Returns the location of this object as a GPoint.
Usage: pt = gobj.getLocation() 
Returns: The location of this object as a GPoint
 


getSize()

Returns the size of the bounding box for this object.
Usage: size = gobj.getSize() 
Returns: The size of this object
 


getWidth()

Returns the width of this object, which is defined to be the width of the bounding box.
Usage: width = gobj.getWidth() 
Returns: The width of this object on the screen
 


getX()

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


getY()

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


isVisible()

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


move(dx, dy)

Moves the object on the screen using the displacements dx and dy.
Usage: gobj.move(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)
 


movePolar(r, theta)

Moves the object using displacements given in polar coordinates. The parameter r specifies the distance to move and theta specifies the angle in which the motion occurs. The angle is measured in degrees increasing counterclockwise from the +x axis.
Usage: gobj.movePolar(r, theta) 
Parameters: 
 The distance to move
theta  The angle in which to move, measured in degrees increasing counterclockwise from the +x axis
 


rotate(theta)

Rotates the object on the screen theta degrees around its origin. Note: The rotate method is not yet implemented.
Usage: gobj.rotate(theta) 
Parameter: 
theta  The angle of rotation in degrees counterclockwise
 


scale(sf)

Scales the object on the screen by the scale factor sf, which applies in both dimensions. Note: The scale method is not yet implemented.
Usage: gobj.scale(sf) 
Parameter: 
sf  The factor used to scale all coordinates in both dimensions
 


sendBackward()

Moves this object one step toward the back in the z dimension. If it was already at the back of the stack, nothing happens.
Usage: gobj.sendBackward() 
 


sendForward()

Moves this object one step toward the front in the z dimension. If it was already at the front of the stack, nothing happens.
Usage: gobj.sendForward() 
 


sendToBack()

Moves this object to the back of the display in the z dimension. 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.sendToBack() 
 


sendToFront()

Moves this object to the front of the display in the z dimension. 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.sendToFront() 
 


setColor(color)

Sets the color of this object.
Usage: gobj.setColor(color) 
Parameter: 
color  The color of this object
 


setLineWidth(width)

Sets the width of the lines used to draw the object.
Usage: gobj.setLineWidth(width) 
Parameter: 
width  The line width in pixels
 


setLocation(x, y)

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


setVisible(flag)

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