| 
 | ||||||||
| 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 makeImagethat 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 Worldtruepublic boolean bigBang(double time)
bigBang in class Worldtime - the timer interval in seconds
true
public boolean bigBang(int width,
                       int height)
bigBang in class Worldwidth - initial window width in pixelsheight - initial window height in pixels
true
public boolean bigBang(int width,
                       int height,
                       double time)
bigBang in class Worldwidth - initial window width in pixelsheight - initial window height in pixelstime - the timer interval in seconds
truepublic World endOfWorld(String s)
gotKeyEvent.
endOfWorld in class Worldmessage - a String to pass on to lastImage, e.g. "Congratulations!  Final score 283."
this worldpublic int getCurrentHeight()
getCurrentHeight in class Worldpublic int getCurrentWidth()
getCurrentWidth in class Worldpublic double getElapsedTime()
getElapsedTime in class Worldpublic int getHeight()
getHeight in class Worldpublic Model getModel()
public int getTickCount()
getTickCount in class Worldpublic 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 AnimationmakeImage, ignoring the string.
lastImage in class Worlds - a String that endOfWorld can use to communicate to lastImage
public WorldImage makeImage()
makeImage in interface DrawablemakeImage in class WorldWorld.makeImage()public abstract WorldImage makeImage(Model oldModel)
oldModel - the current model
public World onKeyEvent(String s)
onKeyEvent in class WorldWorldpublic World onMouseClicked(Posn mouse)
onMouseClicked in class Worldmouse - the location of the mouse when clicked
Worldpublic World onMouseDragged(Posn mouse)
onMouseDragged in class Worldmouse - the location of the mouse when moved
Worldpublic World onMouseEntered(Posn mouse)
onMouseEntered in class Worldmouse - the location of the mouse when entered
Worldpublic World onMouseExited(Posn mouse)
onMouseExited in class Worldmouse - the location of the mouse when exited
Worldpublic World onMouseMoved(Posn mouse)
onMouseMoved in class Worldmouse - the location of the mouse when moved
Worldpublic World onMousePressed(Posn mouse)
onMousePressed in class Worldmouse - the location of the mouse when pressed
WorldWorld.onMousePressed()public World onMouseReleased(Posn mouse)
onMouseReleased in class Worldmouse - the location of the mouse when released
WorldWorld.onMouseReleased()public World onTick()
onTick in class WorldWorldpublic WorldEnd worldEnds()
worldEnds in class Worldpublic 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| 
 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||