|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavalib.funworld.World
public abstract class World
World for programming interactive games - with graphics, key events, mouse events and a timer.
Field Summary | |
---|---|
WorldEnd |
lastWorld
the last world - if needed |
protected MyTimer |
mytime
the timer for this world |
protected boolean |
stopTimer
timer events not processed when the mouse event is processed |
WorldCanvas |
theCanvas
the canvas that displays the current world |
Constructor Summary | |
---|---|
World()
The default constructor. |
Method Summary | |
---|---|
boolean |
bigBang()
Start the world by creating a canvas whose size is that of the initial image, with no timer. |
boolean |
bigBang(double speed)
Start the world by creating a canvas whose size is that of the initial image, and starting the timer at a given speed. |
boolean |
bigBang(int w,
int h)
Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, without running the the timer. |
boolean |
bigBang(int w,
int h,
double speed)
Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, and starting the timer at the given speed. |
protected boolean |
drawWorld(String s)
Invoke the user defined makeImage method, if this
has been initialized
via bigBang and did not stop or end, otherwise
invoke the user defined lastImage method, |
World |
endOfWorld(String s)
End the world interactions - leave the canvas open, show the image of the last world with the given message |
int |
getCurrentHeight()
Get the current height of the animation window (which may have been adjusted by the user). |
int |
getCurrentWidth()
Get the current width of the animation window (which may have been adjusted by the user). |
double |
getElapsedTime()
Getter for elapsed time. |
int |
getHeight()
Get the initially-specified height. |
int |
getTickCount()
Getter for tickCount. |
int |
getWidth()
Get the initially-specified width. |
WorldImage |
lastImage(String s)
User defined method to draw the . |
abstract WorldImage |
makeImage()
User defined method to draw the . |
World |
onKeyEvent(String s)
User defined method to be invoked by the key adapter on selected key events. |
World |
onMouseClicked(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is clicked. |
World |
onMouseDragged(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is dragged. |
World |
onMouseEntered(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is entered. |
World |
onMouseExited(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is exited. |
World |
onMouseMoved(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is moved. |
World |
onMousePressed(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is pressed. |
World |
onMouseReleased(Posn mouse)
User defined method to be invoked by the mouse adapter when a mouse is released. |
World |
onTick()
User defined method to be invoked by the timer on each tick. |
protected World |
processKeyEvent(String ke)
The method invoked by the key adapter on selected key events. |
protected World |
processMouseClicked(Posn mouse)
The method invoked by the mouse adapter on mouse clicked event. |
protected World |
processMouseDragged(Posn mouse)
The method invoked by the mouse adapter on mouse dragged event. |
protected World |
processMouseEntered(Posn mouse)
The method invoked by the mouse adapter on mouse entered event. |
protected World |
processMouseExited(Posn mouse)
The method invoked by the mouse adapter on mouse exited event. |
protected World |
processMouseMoved(Posn mouse)
The method invoked by the mouse adapter on mouse moved event. |
protected World |
processMousePressed(Posn mouse)
The method invoked by the mouse adapter on mouse pressed event. |
protected World |
processMouseReleased(Posn mouse)
The method invoked by the mouse adapter on mouse released event. |
protected World |
processTick()
The method invoked by the timer on each tick. |
protected void |
stopWorld()
Stop the world, close all listeners and the timer, draw the last Scene . |
World |
testOnTick()
The onTick method is invoked only if the world exists. |
WorldEnd |
worldEnds()
This method is invoked at each tick. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public WorldEnd lastWorld
protected transient MyTimer mytime
protected transient boolean stopTimer
public WorldCanvas theCanvas
Constructor Detail |
---|
public World()
bigBang
method.
Method Detail |
---|
public boolean bigBang()
true
public boolean bigBang(double speed)
speed
- the interval between clock ticks, in seconds
true
public boolean bigBang(int w, int h)
w
- the width of the Canvas
h
- the height of the Canvas
true
public boolean bigBang(int w, int h, double speed)
w
- the width of the Canvas
h
- the height of the Canvas
speed
- the speed at which the clock runs
true
protected boolean drawWorld(String s)
makeImage
method, if this
World
has been initialized
via bigBang
and did not stop or end, otherwise
invoke the user defined lastImage
method,
s
- a String to be passed on to lastImage
true
public World endOfWorld(String s)
s
- the message to display
this
worldpublic int getCurrentHeight()
public int getCurrentWidth()
public double getElapsedTime()
public int getHeight()
public int getTickCount()
public int getWidth()
public WorldImage lastImage(String s)
User defined method to draw the
.World
Override this method in the game world class
s
- a String that endOfWorld
can use to communicate to lastImage
public abstract WorldImage makeImage()
User defined method to draw the
.World
Override this method in the game world class
makeImage
in interface Drawable
public World onKeyEvent(String s)
User defined method to be invoked by the key adapter
on selected key events.
Produces a new
.World
Override this method in the game world class
a
- String indicating the key that was pressed.
This will be either a single character (for letters, numbers, punctuation) or
one of the following:
"backspace", "tab", "newline", "escape", "page up", "page down", "end", "home",
"left", "up", "right", "down", "delete", or "f1" through "f12"
World
that needs to have
the canvas and the event handlers initializedpublic World onMouseClicked(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is clicked.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when clicked
World
after the mouse eventpublic World onMouseDragged(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is dragged.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when moved
World
after the mouse eventpublic World onMouseEntered(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is entered.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when entered
World
after the mouse eventpublic World onMouseExited(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is exited.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when exited
World
after the mouse eventpublic World onMouseMoved(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is moved.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when moved
World
after the mouse eventpublic World onMousePressed(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is pressed.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when pressed
World
after the mouse eventpublic World onMouseReleased(Posn mouse)
User defined method to be invoked by the mouse adapter
when a mouse is released.
Update the
.World
Override this method in the game world class
mouse
- the location of the mouse when released
World
after the mouse eventpublic World onTick()
User defined method to be invoked by the timer on each tick.
Produces a new
.World
Override this method in the game world class
World
that needs to have
the canvas and the event handlers initializedprotected World processKeyEvent(String ke)
World
after the key eventprotected World processMouseClicked(Posn mouse)
mouse
- the location of the mouse when clicked
World
after the mouse eventprotected World processMouseDragged(Posn mouse)
mouse
- the location of the mouse when dragged
World
after the mouse eventprotected World processMouseEntered(Posn mouse)
mouse
- the location of the mouse when entered
World
after the mouse eventprotected World processMouseExited(Posn mouse)
mouse
- the location of the mouse when exited
World
after the mouse eventprotected World processMouseMoved(Posn mouse)
mouse
- the location of the mouse when moved
World
after the mouse eventprotected World processMousePressed(Posn mouse)
mouse
- the location of the mouse when pressed
World
after the mouse eventprotected World processMouseReleased(Posn mouse)
mouse
- the location of the mouse when released
World
after the mouse eventprotected World processTick()
World
after the tick eventprotected void stopWorld()
Scene
.
public World testOnTick()
onTick
method is invoked only if the world exists.
To test the method onTick
we provide this method that
will invoke the onTick
method for the testing purposes.
public WorldEnd worldEnds()
This method is invoked at each tick. It checks if the world should end now.
The saved image will be shown when the world ends, otherwise it is ignored.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |