|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectballworld.model.Ball
public class Ball
An abstract ball that moves in a line with its given velocity and bounces off the walls of a rectangularly shaped container. Has a Point representing its center, an int representing its radius, a Point representing its velocity, a Color representing its color.
Field Summary | |
---|---|
private java.awt.Color |
_color
The color of the ball. |
private java.awt.Component |
_container
The Container that is currently holding this ball and defines where the walls are |
private java.awt.Point |
_location
The present location of the center of the ball. |
private IPaintStrategy |
_paintStrategy
The strategy used to paint the ball. |
private int |
_radius
The radius of the ball. |
private IUpdateStrategy |
_updateStrategy
The strategy used to update the state of the ball |
private java.awt.Point |
_velocity
The current velocity of the ball. |
Constructor Summary | |
---|---|
Ball(java.awt.Point p,
int r,
java.awt.Point v,
java.awt.Color c,
java.awt.Component container,
IUpdateStrategy updateStrategy,
IPaintStrategy paintStrategy)
Initializes this Ball to a given center, radius, color, containing walls, and the NullStrategy to move in a straight line. |
Method Summary | |
---|---|
void |
bounce()
Checks if the ball needs to bounce off the wall of its container |
java.awt.Color |
getColor()
Returns the current color of this Ball. |
java.awt.Component |
getContainer()
Accessor for the ball's container Component |
java.awt.Point |
getLocation()
Returns the current center of this Ball. |
IPaintStrategy |
getPaintStrategy()
Returns the current paint strategy of this Ball |
int |
getRadius()
Returns the current radius for this Ball. |
IUpdateStrategy |
getUpdateStrategy()
Returns the current strategy of this Ball |
java.awt.Point |
getVelocity()
Returns the current velocity of this Ball. |
void |
move()
Moves the ball's location by the X and Y increments specified by the velocity property. |
void |
paint(java.awt.Graphics g)
Paints the image of the ball onto a Graphics object. |
void |
setColor(java.awt.Color color)
Sets the color of this Ball to a given color. |
void |
setLocation(java.awt.Point location)
Sets the center to a new location. |
void |
setPaintStrategy(IPaintStrategy pstrategy)
Sets the current strategy of this Ball to the given strategy |
void |
setRadius(int radius)
Sets the radius of this Ball to a new radius. |
void |
setUpdateStrategy(IUpdateStrategy strategy)
Sets the current strategy of this Ball to the given strategy |
void |
setVelocity(java.awt.Point velocity)
Sets the velocity of this Ball to a new velocity. |
void |
update(java.util.Observable o,
java.lang.Object g)
Moves to the new position, updates the attributes of this Ball and paints it. |
void |
updateState()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.awt.Point _location
private int _radius
private java.awt.Point _velocity
private java.awt.Color _color
private java.awt.Component _container
private IUpdateStrategy _updateStrategy
private IPaintStrategy _paintStrategy
Constructor Detail |
---|
public Ball(java.awt.Point p, int r, java.awt.Point v, java.awt.Color c, java.awt.Component container, IUpdateStrategy updateStrategy, IPaintStrategy paintStrategy)
r
- the initial radius of this Ball.v
- the initial velocity of this Ball.c
- The initial color of the ball.p
- the initial center of this Ball.container
- the rectangular Container area where this Ball is drawn.Method Detail |
---|
public void update(java.util.Observable o, java.lang.Object g)
update
in interface java.util.Observer
public void updateState()
public void move()
public void bounce()
public void setLocation(java.awt.Point location)
location
- the new center.public java.awt.Point getLocation()
public void setRadius(int radius)
radius
- public int getRadius()
public void setVelocity(java.awt.Point velocity)
velocity
- the new velocity for this Ball.public java.awt.Point getVelocity()
public void setColor(java.awt.Color color)
color
- the new color for this Ball.public java.awt.Color getColor()
public IUpdateStrategy getUpdateStrategy()
public void setUpdateStrategy(IUpdateStrategy strategy)
strategy
- The new IUpdateStrategy to use.public void paint(java.awt.Graphics g)
g
- a Graphics object.public void setPaintStrategy(IPaintStrategy pstrategy)
pstrategy
- The new IPaintStrategy to use.public IPaintStrategy getPaintStrategy()
public java.awt.Component getContainer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |