|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavalib.funworld.World
javalib.funworld.Animation<Model>
public abstract class Animation<Model>
An easy-to-use class for model/view GUI programs. The Animation class maintains the model as an instance variable and updates it at each event. To use it,
import javalib.funworld.*; class MyAnimation extends Animation<Integer> { // constructors and methods will go here }
public MyAnimation (Integer initial) { super(initial); // maybe do other stuff here }Alternatively, if your animation should always start with the same initial value, you can write a constructor that takes in nothing, e.g.
public MyAnimation () { super(0); // maybe do other stuff here }
public Integer gotTick (Integer old) { return old + 1; }Of course, these methods should have test cases in an accompanying TestMyAnimation class.
makeImage
, which is how the
animation library decides what to show in the animation window. For example, if you wanted to
display a blue disk whose radius was the integer model, you could write
public WorldImage makeImage (Integer current) { return AImage.makeCircle(current, new Blue(), Mode.FILLED); }
new MyAnimation(5).bigBang (300, 200, 0.5);which creates a MyAnimation object with initial model 5 and runs it in a 300x200 window, with the clock ticking every 0.5 second.
Field Summary |
---|
Fields inherited from class javalib.funworld.World |
---|
lastWorld, mytime, stopTimer, theCanvas |
Constructor Summary | |
---|---|
Animation(Model newModel)
Constructor for Animation |
Method Summary | |
---|---|
boolean |
bigBang()
Start an animation, with default size and no timer. |
boolean |
bigBang(double time)
Start an animation, with default size and a specified timer interval. |
boolean |
bigBang(int width,
int height)
Start an animation, with specified size and no timer. |
boolean |
bigBang(int width,
int height,
double time)
Start an animation, with specified size and timer interval. |
World |
endOfWorld(String s)
End the animation now. |
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()
Get elapsed time so far. |
int |
getHeight()
Get the initially-specified height. |
Model |
getModel()
Get the current model. |
int |
getTickCount()
Get number of ticks so far. |
int |
getWidth()
Get the initially-specified width. |
Model |
gotKeyEvent(Model oldModel,
String s)
Produce the new model after a keyboard event. |
Model |
gotMouseClicked(Model oldModel,
Posn mouse)
Produce the new model after a mouse-click event. |
Model |
gotMouseDragged(Model oldModel,
Posn mouse)
Produce the new model after a mouse-drag event. |
Model |
gotMouseEntered(Model oldModel,
Posn mouse)
Produce the new model after the mouse enters the window. |
Model |
gotMouseExited(Model oldModel,
Posn mouse)
Produce the new model after the mouse leaves the window. |
Model |
gotMouseMoved(Model oldModel,
Posn mouse)
Produce the new model after a mouse-move event. |
Model |
gotMousePressed(Model oldModel,
Posn mouse)
Produce the new model after the mouse is pressed (but not yet released). |
Model |
gotMouseReleased(Model oldModel,
Posn mouse)
Produce the new model after the mouse is released. |
Model |
gotTick(Model oldModel)
Produce the new model after a tick event. |
WorldImage |
lastImage(String s)
An alternative to makeImage that is called when the animation ends. |
WorldImage |
makeImage()
A version of makeImage(Model) that defaults to using the current Model. |
abstract WorldImage |
makeImage(Model oldModel)
Produce a WorldImage representation of the model; users subclassing Animation must override this. |
World |
onKeyEvent(String s)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseClicked(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseDragged(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseEntered(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseExited(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseMoved(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMousePressed(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onMouseReleased(Posn mouse)
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
World |
onTick()
User shouldn't need to use or override this method, unless you're doing something with the World more complicated than just replacing the Model. |
WorldEnd |
worldEnds()
User shouldn't need to use or override this method. |
WorldEnd |
worldEnds(Model oldModel)
Decide whether the animation should end yet, and if so, what the final window should look like. |
Methods inherited from class javalib.funworld.World |
---|
drawWorld, processKeyEvent, processMouseClicked, processMouseDragged, processMouseEntered, processMouseExited, processMouseMoved, processMousePressed, processMouseReleased, processTick, stopWorld, testOnTick |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Animation(Model newModel)
public MyKindOfAnimation (Model newModel) { super(newModel); // other initialization can go here }
newModel
- the initial model for the Animation.Method Detail |
---|
public boolean bigBang()
bigBang
in class World
true
public boolean bigBang(double time)
bigBang
in class World
time
- the timer interval in seconds
true
public boolean bigBang(int width, int height)
bigBang
in class World
width
- initial window width in pixelsheight
- initial window height in pixels
true
public boolean bigBang(int width, int height, double time)
bigBang
in class World
width
- initial window width in pixelsheight
- initial window height in pixelstime
- the timer interval in seconds
true
public World endOfWorld(String s)
gotKeyEvent
.
endOfWorld
in class World
message
- a String to pass on to lastImage
, e.g. "Congratulations! Final score 283."
this
worldpublic int getCurrentHeight()
getCurrentHeight
in class World
public int getCurrentWidth()
getCurrentWidth
in class World
public double getElapsedTime()
getElapsedTime
in class World
public int getHeight()
getHeight
in class World
public Model getModel()
public int getTickCount()
getTickCount
in class World
public int getWidth()
getWidth
in class World
public Model gotKeyEvent(Model oldModel, String s)
oldModel
- the current models
- the key that was pressed public Model gotMouseClicked(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMouseDragged(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMouseEntered(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMouseExited(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMouseMoved(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMousePressed(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotMouseReleased(Model oldModel, Posn mouse)
oldModel
- the current modelmouse
- the location of the mouse
public Model gotTick(Model oldModel)
oldModel
- the current model
public WorldImage lastImage(String s)
makeImage
that is called when the animation ends.
You'll often want to override this method in your Animation
class;
if you don't, it'll just call makeImage
, ignoring the string.
lastImage
in class World
s
- a String that endOfWorld
can use to communicate to lastImage
public WorldImage makeImage()
makeImage
in interface Drawable
makeImage
in class World
World.makeImage()
public abstract WorldImage makeImage(Model oldModel)
oldModel
- the current model
public World onKeyEvent(String s)
onKeyEvent
in class World
World
that needs to have
the canvas and the event handlers initializedpublic World onMouseClicked(Posn mouse)
onMouseClicked
in class World
mouse
- the location of the mouse when clicked
World
after the mouse eventpublic World onMouseDragged(Posn mouse)
onMouseDragged
in class World
mouse
- the location of the mouse when moved
World
after the mouse eventpublic World onMouseEntered(Posn mouse)
onMouseEntered
in class World
mouse
- the location of the mouse when entered
World
after the mouse eventpublic World onMouseExited(Posn mouse)
onMouseExited
in class World
mouse
- the location of the mouse when exited
World
after the mouse eventpublic World onMouseMoved(Posn mouse)
onMouseMoved
in class World
mouse
- the location of the mouse when moved
World
after the mouse eventpublic World onMousePressed(Posn mouse)
onMousePressed
in class World
mouse
- the location of the mouse when pressed
World
after the mouse eventWorld.onMousePressed()
public World onMouseReleased(Posn mouse)
onMouseReleased
in class World
mouse
- the location of the mouse when released
World
after the mouse eventWorld.onMouseReleased()
public World onTick()
onTick
in class World
World
that needs to have
the canvas and the event handlers initializedpublic WorldEnd worldEnds()
worldEnds
in class World
public WorldEnd worldEnds(Model oldModel)
worldEnds
is the way to do it.
You'll probably never call this method, except for unit-testing,
but you may well want to override it. If you don't, the default handler says
"no, don't end the world."
oldModel
- the current model
WorldImage
to use as the final contents of the animation window.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |