|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectWorld
public class World
World is a class representing an environment for Turtles. The world is visualized as a window, and its size can be selected upon construction. As the turtles move around, they are redrawn and they leave tracks on the background in the form of their linear path.
Constructor Summary | |
---|---|
World()
Constructs a world with default size of 400 by 400 pixels. |
|
World(int width,
int height)
Constructs a world with a specified width and height. |
Method Summary | |
---|---|
(package private) void |
add(Turtle t)
Package local method which adds a turtle to this world. |
void |
disableUpdateOnChange()
Disables update on change. |
(package private) void |
drawPath(Turtle t,
int xOld,
int yOld,
int xNew,
int yNew)
Package local method which draws a line from an old position to the new for a given turtle. |
void |
enableUpdateOnChange()
Enables update on change. |
int |
getHeight()
Returns the height of the world in pixels. |
boolean |
getUpdateOnChange()
Returns the current update on change flag. |
int |
getWidth()
Returns the width of the world in pixels. |
void |
remove(Turtle t)
Removes a turtle from the world. |
String |
toString()
Generates a string representation of the world and all the turtles in it. |
(package private) void |
turtleUpdate()
Signals that a Turtle has been updated. |
void |
update()
Forces a repaint of the world. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public World()
public World(int width, int height)
width
- The width of the world in pixels.height
- The height of the world in pixels.Method Detail |
---|
public void remove(Turtle t)
t
- A reference to the turtle to remove.public int getWidth()
public int getHeight()
public boolean getUpdateOnChange()
Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.
public void enableUpdateOnChange()
Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.
public void disableUpdateOnChange()
Update on change causes the world to be redrawn for every state change of a Turtle connected to this World.
public void update()
public String toString()
toString
in class Object
void add(Turtle t)
t
- Turtle to be added to the world.void turtleUpdate()
void drawPath(Turtle t, int xOld, int yOld, int xNew, int yNew)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |