ClickAction
CircleShape
, SquareShape
, TextShape
public class Shape extends Widget
Window
. This class is an abstract class for students to
implement their graphics objects.
The color, location, and size can be specified in constructors. The shapes
are self contained and support clicking on them, dragging them, and changing
the color, size, and location via methods on its interface.Constructor | Description |
---|---|
Shape(int x,
int y) |
Builds a Shape at the indicated x and y indices, of default size 50 and
color orange.
|
Shape(int x,
int y,
int size) |
Builds a shape of the specified size and indices, with default color
orange.
|
Shape(int x,
int y,
int width,
int height) |
Builds a shape of the specified size and indices, with default color
orange.
|
Shape(int x,
int y,
int width,
int height,
java.awt.Color color) |
|
Shape(int x,
int y,
int size,
java.awt.Color color) |
Builds a shape of the specified size, color, and indicies.
|
Shape(int x,
int y,
java.awt.Color color) |
Builds a shape of the specified color and indices, with default size 50.
|
Modifier and Type | Method | Description |
---|---|---|
void |
draw(java.awt.Graphics2D graph) |
Draws this shape.
|
boolean |
equals(java.lang.Object obj) |
Equals method for shapes.
|
int |
getHeight() |
getter for the height of the shape
|
int |
getWidth() |
getter for the width of the shape
|
void |
move(int dx,
int dy) |
Changes the Shape's location by the indicated amounts.
|
void |
moveTo(int x,
int y) |
Sets the Shape's location to be the indicated indices.
|
void |
onClick(Command scl) |
onClick third version of this method, this one uses a listener object of
type Command.
|
void |
onClick(java.lang.Object object,
java.lang.String methodName) |
onClick - another version of callOnClick, this one specifies the method
to call in the parameter.
|
void |
onTimer(int interval,
Command cmd) |
Animate this Object.
|
void |
onTimer(int interval,
java.lang.Object obj,
java.lang.String method) |
Animate this object.
|
void |
remove() |
|
void |
stopTimer() |
Stops the timer on this shape, if it exists, and sets it to null.
|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
collidesWith, contains, getBackgroundColor, getBounds, getForegroundColor, getWindow, getX, getY, onClick, repaint, setBackgroundColor, setForegroundColor, setX, setY
public Shape(int x, int y)
x
- the x index in pixelsy
- the y index in pixelspublic Shape(int x, int y, int size)
x
- the x index in pixelsy
- the y index in pixelssize
- the width and height of the shapepublic Shape(int x, int y, int width, int height)
x
- - the x index in pixelsy
- - the y index in pixelswidth
- - the width of the shapeheight
- - the height of the shapepublic Shape(int x, int y, int width, int height, java.awt.Color color)
public Shape(int x, int y, java.awt.Color color)
x
- the x index in pixelsy
- the y index in pixelscolor
- the Color of the shapepublic Shape(int x, int y, int size, java.awt.Color color)
x
- the x index in pixelsy
- the y index in pixelssize
- the width and height of the shapecolor
- the Color of the shapepublic int getWidth()
public int getHeight()
public void move(int dx, int dy)
dx
- the amount in pixels to move along the x axisdy
- the amount in pixels to move along the y axispublic void moveTo(int x, int y)
x
- the x index in pixelsy
- the y index in pixelspublic void draw(java.awt.Graphics2D graph)
graph
- graphics object from Swingpublic void onClick(java.lang.Object object, java.lang.String methodName)
ClickAction
onClick
in interface ClickAction
onClick
in class Widget
object
- receives the call upon click, can't be nullmethodName
- name of method to be called, can't be nullapply.
if the method doesn't exist, this will generate an exception
(NoSuchMethod).
public void onClick(Command scl)
onClick
in interface ClickAction
onClick
in class Widget
scl
- command object, can't be nullpublic void onTimer(int interval, java.lang.Object obj, java.lang.String method)
interval
- The delay in millisecondsobj
- the Object to animatemethod
- the name of the method which provides the animationpublic void onTimer(int interval, Command cmd)
interval
- The delay in millisecondscmd
- the Command to execute on Timer.public void stopTimer()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- other Object to compare to