Methods Summary |
---|
public int | getAnimationRate()
return rate;
|
public java.awt.Dimension | getMinimumSize()
return new Dimension(144, 125);
|
public java.awt.Dimension | getPreferredSize()
return getMinimumSize();
|
private void | initialize()Initialize the Juggler .
// Load the image resources:
images = new Image[5];
for (int i = 0; i < 5; i++) {
String imageName = "Juggler" + i + ".gif";
images[i] = loadImage(imageName);
if (images[i] == null) {
System.err.println("Couldn't load image " + imageName);
return;
}
}
|
public boolean | isDesignTime()
return dmode;
|
public boolean | isJuggling()Returns false if the Juggler is stopped, true otherwise.
return !stopped;
|
private java.awt.Image | loadImage(java.lang.String name)This is an internal utility method to load GIF icons.
It takes the name of a resource file associated with the
current object's class-loader and loads a GIF image
from that file.
try {
java.net.URL url = getClass().getResource(name);
ImageIcon icon = new ImageIcon(url);
Image i = icon.getImage();
return i;
} catch (Exception ex) {
return null;
}
|
public void | paintComponent(java.awt.Graphics g)Draw the current frame.
int index = (loop%4) + 1;
// If the animation is stopped, show the startup image.
if (stopped) {
index = 0;
}
if (images == null || index >= images.length) {
return;
}
Image img = images[index];
if (img != null) {
g.drawImage(img, 0, 0, this);
}
|
public void | propertyChange(java.beans.PropertyChangeEvent evt)
if (evt.getPropertyName().equals("designMode")) {
boolean dmode = (boolean)((Boolean)evt.getNewValue()).booleanValue();
setDesignTime(dmode);
}
|
private void | readObject(java.io.ObjectInputStream s)
s.defaultReadObject();
initialize();
if ( !stopped )
start();
|
public void | run()
try {
while(true) {
// First wait until the animation is not stopped.
synchronized (this) {
while (stopped || !isEnabled()) {
wait();
}
}
loop++;
// Now draw the current frame.
Graphics g = getGraphics();
Image img = images[(loop % 4) + 1];
if (g != null && img != null) {
g.drawImage(img, 0, 0, this);
}
Thread.sleep(rate);
}
} catch (InterruptedException e) {
}
|
public void | setAnimationRate(int x)
rate = x;
|
public void | setDesignTime(boolean dmode)
this.dmode = dmode;
|
public synchronized void | setEnabled(boolean x)If false, suspend the animation thread.
super.setEnabled(x);
notify();
|
public void | setJuggling(boolean b)
if ( b )
start();
else
stop();
|
public synchronized void | start()method: start the Juggler .
startJuggling();
|
public void | startJuggling(java.awt.event.ActionEvent x)An event handling method that calls startJuggling. This method
can be used to connect a Button or a MenuItem to the Juggler.
startJuggling();
|
public synchronized void | startJuggling()Resume the animation thread if we're enabled.
if (images == null) {
initialize();
}
if (animationThread == null) {
animationThread = new Thread(this);
animationThread.start();
}
stopped = false;
notify();
|
public synchronized void | stop()method: stop the Juggler .
stopJuggling();
|
public void | stopJuggling(java.awt.event.ActionEvent x)This method can be used to connect a Button or a MenuItem
to the Juggler.stopJuggling method.
stopJuggling();
|
public synchronized void | stopJuggling()Suspend the animation thread if neccessary.
stopped = true;
loop = 0;
// Draw the stopped frame.
Graphics g = getGraphics();
if (g == null || images == null) {
return;
}
Image img = images[0];
if (img != null) {
g.drawImage(img, 0, 0, this);
}
|