Constructor and Description |
---|
GObject()
Constructs a new empty object.
|
GObject(GCanvas canvas)
Constructs a new empty object and adds it to the given canvas.
|
Modifier and Type | Method and Description |
---|---|
GObject |
addTo(GCanvas canvas)
Adds this GObject to the given graphical canvas.
|
GObject |
addTo(GCanvas canvas,
float x,
float y)
Adds this GObject to the given graphical canvas.
|
GObject |
addTo(GCanvas canvas,
GPoint location)
Adds this GObject to the given graphical canvas.
|
boolean |
contains(float x,
float y)
Checks to see whether a point is inside the object.
|
boolean |
contains(GPoint pt)
Checks to see whether a point is inside the object.
|
float |
getBottomY()
Returns the max Y of this object.
|
GRectangle |
getBounds()
Returns the bounding box of this object, which is defined to be
the smallest rectangle that covers everything drawn by the figure.
|
float |
getCenterX()
Returns the x-value of the center of this object.
|
float |
getCenterY()
Returns the y-value of the center of this object.
|
Paint |
getColor()
Returns the color used to display this object.
|
Paint |
getFillColor()
Returns the color used to display the filled region of this object.
|
GCanvas |
getGCanvas()
Returns the simple canvas this GObject is drawn inside of.
|
float |
getHeight()
Returns the height of this object, which is defined to be the height of the bounding box.
|
float |
getLeftX()
Returns this object's leftmost x-coordinate.
|
GPoint |
getLocation()
Returns the location of this object as a GPoint.
|
Paint |
getPaint()
Returns the color used to display this object.
|
float |
getRightX()
Returns the max X of this object.
|
GDimension |
getSize()
Returns the size of the bounding box for this object.
|
float |
getTopY()
Returns this object's top y-coordinate.
|
float |
getWidth()
Returns the width of this object, which is defined to be the width of the bounding box.
|
float |
getX()
Returns the x-coordinate of the object.
|
float |
getY()
Returns the y-coordinate of the object.
|
boolean |
intersects(GObject obj)
True if this object touches the other object.
|
boolean |
isFilled()
Returns whether this object is filled.
|
boolean |
isVisible()
Checks to see whether this object is visible.
|
GObject |
moveBy(float dx,
float dy)
Moves the object on the screen using the displacements dx and dy.
|
GObject |
moveByPolar(float r,
float theta)
Moves the object using displacements given in polar coordinates.
|
GObject |
moveTo(float x,
float y)
Moves the object on the screen to the given x/y position.
|
GObject |
moveTo(GObject gobj)
Moves this GObject to have the same location as the given other GObject.
|
GObject |
moveTo(GPoint point)
Moves the object on the screen to the given point's x/y position.
|
GObject |
moveToPolar(float r,
float theta)
Moves the object using displacements given in polar coordinates.
|
abstract void |
paint(Canvas canvas)
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.
|
GObject |
remove()
Removes this object from its graphical canvas, if it is added to one.
|
void |
repaint()
Instructs this object to redraw itself by calling the postInvalidate method
on its enclosing GCanvas as needed.
|
GObject |
scale(float sf)
Scales the object on the screen by the scale factor
sf , which applies
in both dimensions. |
GObject |
scale(float sx,
float sy)
Scales the object on the screen by the scale factors
sx and sy . |
GObject |
sendBackward()
Moves this object one step toward the back in the z dimension.
|
GObject |
sendForward()
Moves this object one step toward the front in the z dimension.
|
GObject |
sendToBack()
Moves this object to the back of the display in the z dimension.
|
GObject |
sendToFront()
Moves this object to the front of the display in the z dimension.
|
GObject |
setBottomY(float bottomY)
Sets the object's bottom y-coordinate to be the given value.
|
GObject |
setBounds(float x,
float y,
float width,
float height)
Changes the bounds of this object to the specified values.
|
GObject |
setBounds(GPoint location,
GDimension size)
Changes the bounds of this object to the specified values.
|
GObject |
setBounds(GRectangle bounds)
Changes the bounds of this object to the values from the specified
GRectangle . |
GObject |
setCanvas(Canvas canvas)
Sets the canvas this object is in.
|
GObject |
setColor(Paint paint)
Sets the color used to display this object.
|
GObject |
setFillColor(Paint color)
Sets the color used to display the filled region of this object.
|
GObject |
setFilled(boolean fill)
Sets whether this object is filled.
|
GObject |
setGCanvas(GCanvas gcanvas)
Sets the canvas on which this GObject should be drawn.
|
GObject |
setLocation(float x,
float y)
Sets the location of this object to the point (x, y).
|
GObject |
setLocation(GObject gobj)
Moves this GObject to have the same location as the given other GObject.
|
GObject |
setLocation(GPoint point)
Sets the location of this object to the given point's (x, y) location.
|
GObject |
setPaint(Paint paint)
Sets the paint used to display this object.
|
GObject |
setRightX(float rightX)
Sets the object's rightmost x-coordinate to be the given value.
|
GObject |
setSize(float width,
float height)
Changes the size of this object to the specified width and height.
|
GObject |
setSize(GDimension size)
Changes the size of this object to the specified
GDimension . |
GObject |
setVisible(boolean visible)
Sets whether this object is visible.
|
GObject |
setX(float x)
Sets the x-location of this object.
|
GObject |
setY(float y)
Sets the y-location of this object.
|
String |
toString()
Returns a string representation of this object, including its
class name, x/y coordinates, width, and height.
|
GObject |
translate(float dx,
float dy)
Moves the object on the screen using the displacements dx and dy.
|
public GObject()
public GObject(GCanvas canvas)
public GObject addTo(GCanvas canvas)
public GObject addTo(GCanvas canvas, float x, float y)
public GObject addTo(GCanvas canvas, GPoint location)
public boolean contains(float x, float y)
public boolean contains(GPoint pt)
NullPointerException
- if pt is nullpublic final float getBottomY()
public GRectangle getBounds()
public final float getCenterX()
public final float getCenterY()
public final Paint getColor()
public final Paint getFillColor()
getFillColor
returns the color of the
object.public final GCanvas getGCanvas()
public float getHeight()
public float getLeftX()
public final GPoint getLocation()
public final Paint getPaint()
public final float getRightX()
public final GDimension getSize()
public float getTopY()
public float getWidth()
public float getX()
public float getY()
public final boolean intersects(GObject obj)
NullPointerException
- if obj is nullpublic final boolean isFilled()
public final boolean isVisible()
public final GObject moveBy(float dx, float dy)
public final GObject moveByPolar(float r, float theta)
public GObject moveTo(float x, float y)
public final GObject moveTo(GObject gobj)
NullPointerException
- if gobj is nullpublic GObject moveTo(GPoint point)
public final GObject moveToPolar(float r, float theta)
public abstract void paint(Canvas canvas)
public GObject remove()
public void repaint()
public GObject scale(float sx, float sy)
sx
and sy
.sx
- The factor used to scale all coordinates in the x directionsy
- The factor used to scale all coordinates in the y directionIllegalArgumentException
- if sx or sy is not a positive numberpublic GObject scale(float sf)
sf
, which applies
in both dimensions.sf
- The factor used to scale all coordinates in both dimensionsIllegalArgumentException
- if sf is not a positive numberpublic final GObject sendBackward()
public final GObject sendForward()
public final GObject sendToBack()
public final GObject sendToFront()
public GObject setBottomY(float bottomY)
public GObject setBounds(float x, float y, float width, float height)
x
- The new x-coordinate for the objecty
- The new y-coordinate for the objectwidth
- The new width of the objectheight
- The new height of the objectIllegalArgumentException
- if width or height is negativepublic GObject setBounds(GPoint location, GDimension size)
location
- The new x/y-coordinates for the objectsize
- The new width/height of the objectIllegalArgumentException
- if width or height is negativepublic GObject setBounds(GRectangle bounds)
GRectangle
.bounds
- A GRectangle
specifying the new boundsIllegalArgumentException
- if rect's width or height is negativepublic final GObject setCanvas(Canvas canvas)
public GObject setColor(Paint paint)
NullPointerException
- if paint is null.public GObject setFillColor(Paint color)
color
- The color used to display the filled region of this objectNullPointerException
- if color is nullpublic GObject setFilled(boolean fill)
fill
- true
if the object should be filled, false
for an outlinepublic GObject setGCanvas(GCanvas gcanvas)
public GObject setLocation(float x, float y)
public GObject setLocation(GPoint point)
public GObject setLocation(GObject gobj)
NullPointerException
- if gobj is null.public GObject setPaint(Paint paint)
NullPointerException
- if paint is null.public GObject setRightX(float rightX)
public GObject setSize(GDimension size)
GDimension
.size
- A GDimension
object specifying the sizeNullPointerException
- if size is nullpublic GObject setSize(float width, float height)
width
- The new width of the objectheight
- The new height of the objectIllegalArgumentException
- if width or height is negativepublic GObject setVisible(boolean visible)
public GObject setX(float x)
public GObject setY(float y)
public String toString()
public GObject translate(float dx, float dy)