![]() |
AnimationWorld: Animation Players |
To play our animations, we just extend a preexisting AnimationPlayer implementation. Two animation players are currently available.
To create an Animation Player for our animation, we extend one of the two
players above, and implement a default constructor method. In the constructor we
create an instance of our animations and add them to the player via the
addAnimation(String name, Animation a) method.
The SimpleAnimationPlayer will ignore all animations added but the first
one. The choice list for the AnimationShowcase will be in the order that
animations are added to the player. The name is required and is displayed
in the interface.
The following methods may also be used to configure the appearance of the animation player. All methods are available for both players.
setScreenColor(Color c)hideResetButton()hidePlayButton()hideStopButton()hideNextButton()hideGotoButton()hideFrameNumberDisplay()hideControlPanel()The following methods may be used to configure when the animation plays automatically. By default, animations are not played until users hit the PLAY button. Animations automatically stop when the user leaves the web page (goes to another web page) or when the web browser window loses focus.
setPlayOnStart()setPlayOnPaint()setPlayOnSelection() AnimationShowcase only
BuggleAnimationPlayer1
Extending the SimpleAnimationPlayer
public class BuggleAnimationPlayer1 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer1 ()
{
addAnimation("RightBuggle", new BuggleAnimation1());
}
}
BuggleAnimationPlayer2
public class BuggleAnimationPlayer2 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer2 ()
{
addAnimation("RightLeftBuggle", new BuggleAnimation2());
}
}
BuggleAnimationPlayer3
public class BuggleAnimationPlayer3 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer3 ()
{
setPlayOnStart();
addAnimation("SpyBuggle", new BuggleAnimation3());
}
}
BuggleAnimationPlayer4
public class BuggleAnimationPlayer4 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer4 ()
{
setScreenColor(new Color(128,0,0)); // maroon
setPlayOnPaint();
addAnimation("SpyArmy", new BuggleAnimation4());
}
}
BuggleAnimationPlayer5
public class BuggleAnimationPlayer5 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer5 ()
{
hideControlPanel();
setPlayOnStart();
addAnimation("SpyArmyII", new BuggleAnimation5());
}
}
BuggleAnimationPlayer6
import java.awt.*; // use colors
public class BuggleAnimationPlayer6 extends SimpleAnimationPlayer
{
public BuggleAnimationPlayer6 ()
{
hideControlPanel();
setPlayOnPaint();
addAnimation("SpyArmyIII", new BuggleAnimation5(Color.green,Color.blue,Color.red,Color.cyan,Color.magenta));
}
}
BugglesInAndOut
public class BugglesInAndOut extends SimpleAnimationPlayer
{
public BugglesInAndOut ()
{
hideNextButton();
hideGotoButton();
hideFrameNumberDisplay();
addAnimation("BugglesInAndOut", new BuggleAnimation6());
}
}
BuggleShowcase
import java.awt.*; // use colors
public class BuggleShowcase extends AnimationShowcase
{
public BuggleShowcase ()
{
setPlayOnSelection();
addAnimation("RightBuggle", new BuggleAnimation1());
addAnimation("RightLeftBuggle", new BuggleAnimation2());
addAnimation("SpyBuggle", new BuggleAnimation3());
addAnimation("SpyArmy", new BuggleAnimation4());
addAnimation("SpyArmyII", new BuggleAnimation5());
addAnimation("SpyArmyIII", new BuggleAnimation5(Color.green,Color.blue,Color.red,Color.cyan,Color.magenta));
addAnimation("Buggles In and Out", new BuggleAnimation6());
}
}