Class jovial.slotCar.animator.Animator
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jovial.slotCar.animator.Animator

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----jovial.slotCar.animator.Animator

public class Animator
extends Canvas
implements Runnable
A class representing an animated Canvas. This canvas constantly moves its components forward in time, and asks them to re-draw themselves. It uses double-buffering to prevent flashiness.

This class interacts with two others: Animatee, and Drawable. At start-up, it is configured with a number of drawables. It then enters a loop, where it tells the Animatee to move (by a time interval), then it draws its Drawables (in increasing order of height, so that overlapping works).

As a concession to efficiency, we adopted the convention that Drawables with a height <= 0 won't be re-drawn in each successive frame. Think of them as a "background" image. In addition, Drawables that canMove() are asked to erase() themselves after each frame. If these restrictions are too much, you can always make sure all your Drawables have a height >= 1, and maybe make your lowest Drawable be a rectangle that erases the entire screen.

Use:

	Animator a = new Animator(myAnimatee);
	new Thread(a).start();
 
See Also:
Animatee, Drawable

Constructor Index

 o Animator()
Initialize a new animator.

Method Index

 o addDrawable(Drawable)
Add to the list of things that we draw
 o init(Animatee)
Initialize us with an animatee.
 o paint(Graphics)
Paint this canvas
 o preferredSize()
Give our preferred size
 o run()
Cause this animator to start running.

Constructors

 o Animator
  public Animator()
Initialize a new animator. Be sure to call init() with the animatee later!

Methods

 o init
  public void init(Animatee a)
Initialize us with an animatee. Should be called from the Animatee's constructor.
Parameters:
a - What we are to animate
 o paint
  public void paint(Graphics g)
Paint this canvas
Overrides:
paint in class Canvas
 o preferredSize
  public Dimension preferredSize()
Give our preferred size
Returns:
the size
Overrides:
preferredSize in class Component
 o addDrawable
  public void addDrawable(Drawable d)
Add to the list of things that we draw
Parameters:
d - The new drawable
 o run
  public void run()
Cause this animator to start running.

All Packages  Class Hierarchy  This Package  Previous  Next  Index