|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectballworlds.framework.World
public class World
A World simulates a "world" that contain various kinds of "balls" (and possibly other objects).
A World constructs its visual elements:
A World manages its Balls, including animating them by calling each Ball's act method repeatedly.
A World manages its Bumpers and other objects that the World creates.
| Constructor Summary | |
|---|---|
World(Dimension size,
Color color,
JFrame ballWorldFrame)
Sets the World's Shape (and related data) and Color to the given values. |
|
| Method Summary | |
|---|---|
void |
addBall(Ball ballToAdd)
Adds the given Ball to this World. |
void |
drawBalls(Graphics2D graphics,
Ball selectedBall)
Draws the Balls in this World. |
Color |
getColor()
Returns the Color of this World. |
Shape |
getShape()
Returns the Shape (which contains position and size) of this World. |
boolean |
isInsideWorldX(Point2D p)
Returns true if the given point's x-coordinate is inside this World. |
boolean |
isInsideWorldY(Point2D p)
Returns true if the given point's y-coordinate is inside this World. |
Point2D |
middleOfWorld()
Returns a new Point2D that is at the middle of this World. |
Ball |
nearestBall(Point2D p)
Returns the Ball in this World that is nearest the given point. |
void |
removeBall(Ball ballToRemove)
Removes the given Ball from this World. |
void |
run()
Repeatedly asks each Ball to act. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public World(Dimension size,
Color color,
JFrame ballWorldFrame)
Constructs the visual elements of this World:
Starts a Thread that repeatedly asks each Ball to act.
size - Size of this World (including its ButtonPanel).color - Color of this World.ballWorldFrame - JFrame to which the visual elements of this World are to be added.| Method Detail |
|---|
public void addBall(Ball ballToAdd)
addBall in interface BallEnvironmentballToAdd - the Ball to add to the World.public void removeBall(Ball ballToRemove)
removeBall in interface BallEnvironmentballToRemove - the Ball to remove from the World.public boolean isInsideWorldX(Point2D p)
isInsideWorldX in interface BallEnvironmentp - the point whose x-coordinate to check
public boolean isInsideWorldY(Point2D p)
isInsideWorldY in interface BallEnvironmentp - the point whose y-coordinate to check
public Point2D middleOfWorld()
middleOfWorld in interface BallEnvironmentpublic Ball nearestBall(Point2D p)
nearestBall in interface CollectionOfBallsp - the point for which to find the nearest Ball.
public void drawBalls(Graphics2D graphics,
Ball selectedBall)
drawBalls in interface CollectionOfBallsgraphics - the object onto which to draw.selectedBall - the ball which has been selected (null if none).public Shape getShape()
getShape in interface Drawablepublic Color getColor()
getColor in interface Drawablepublic void run()
run in interface Runnable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||