Class Shape
java.lang.Object
|
+--Subject
|
+--Shape
- Direct Known Subclasses:
- Circle, GString, Rectangle, Square
- public abstract class Shape
- extends Subject
A Shape is a Subject (so can be observed)
it has a position and a color (all of which can be modified).
Constructor Summary |
Shape(java.awt.Color c,
int x,
int y)
Initialize a new Shape with specified Color and position |
Method Summary |
void |
display(java.awt.Graphics g)
display this using the given pen |
java.awt.Color |
getColor()
|
int |
getX()
|
int |
getY()
|
void |
setColor(java.awt.Color c)
Set the Color of this and notify our observers |
void |
setPosition(int x,
int y)
Set the position of this and then notify our observers |
void |
setX(int x)
Set the x coordinate of this and notify our observers |
void |
setY(int y)
Set the y coordinate of this and notify our observers |
java.lang.String |
toString()
|
Methods inherited from class Subject |
attachObserver,
detachObserver,
notifyObserver |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Shape
public Shape(java.awt.Color c,
int x,
int y)
- Initialize a new Shape with specified Color and position
- Parameters:
c
- the desired colorx
- the desired x coordinatey
- the desired x coordinate
setPosition
public void setPosition(int x,
int y)
- Set the position of this and then notify our observers
- Parameters:
x
- the new x coordinatey
- the new x coordinate
setX
public void setX(int x)
- Set the x coordinate of this and notify our observers
- Parameters:
x
- the new x coordinate
setY
public void setY(int y)
- Set the y coordinate of this and notify our observers
- Parameters:
y
- the new y coordinate
setColor
public void setColor(java.awt.Color c)
- Set the Color of this and notify our observers
- Parameters:
c
- the new Color
getX
public int getX()
- Returns:
- the x coordinate of this
getY
public int getY()
- Returns:
- the y coordinate of this
getColor
public java.awt.Color getColor()
- Returns:
- the Color of this
toString
public java.lang.String toString()
- Returns:
- a String representation of this
- Overrides:
- toString in class java.lang.Object
display
public void display(java.awt.Graphics g)
- display this using the given pen
- Parameters:
g
- the pen we use to display this