All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.AnimatedButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.ImageButton
                           |
                           +----tea.set.AnimatedButton

public class AnimatedButton
extends ImageButton
implements Runnable
AnimatedButton displays a series of animation images in a button. It plays an animation sequence when it is first created and when the mouse pointer moves inside the button. The gif's can be plain images. The images will be passed through a ButtonFilter to create a button image. The rate of the animation can be controlled by setting the delay between frames by using setDelay() method.

The default size of the button is the size of the first image in the animation sequence. If the subsequent images have different size than the first image, they will be scaled to the same size as the first image. If the button is resized to another size, such as the case when the button is added to the Center portion of a panel with BorderLayout, all images will be scaled to the new size to fill the button area.

AnimatedButton supports a text label to be displayed as part of the button. The position of the label can be controlled by position flags. The label is not animated.

The AniamgedButton supports the following preperties in addition to the properties defined in the ImageButton:
Property NameProperty TypeDescription
Delayint Time delay in miniseconds between animation frames.
ImagesImage (Indexed) Animation frames for the AnimatedButton.

See Also:
ImageButton

Constructor Index

 o AnimatedButton()
Construct an empty AnimatedButton.
 o AnimatedButton(Image[])
Create an AnimatedButton with the image array as the animation frames.
 o AnimatedButton(Image[], String)
Create an AnimatedButton with the image array as the animation frames and a text label.
 o AnimatedButton(Image[], String, int)
Create an AnimatedButton with the image array as the animation frames, and a text label with position specification.

Method Index

 o getDelay()
Get the delay value.
 o getImages()
Get the animation frame images array.
 o paint(Graphics)
Paint AnimatedButton.
 o processMouseEvent(MouseEvent)
Mouse enter event starts an animation sequence.
 o run()
Run method of the Runnable interface.
 o setDelay(int)
Set the delay between animation frames in miniseconds.
 o setImages(Image[])
Set the animation frame images.
 o start()
Start the animation sequence.
 o stop()
Stop the animation.
 o update(Graphics)
Override the default update to avoid flickering.

Constructors

 o AnimatedButton
 public AnimatedButton()
Construct an empty AnimatedButton. AnimatedButton.setImages() must be called before this component can be used.

 o AnimatedButton
 public AnimatedButton(Image iv[])
Create an AnimatedButton with the image array as the animation frames. The images don't need to be loaded at the time of the creation of button.

Parameters:
iv - an array of java.awt.Image for animation frames.
 o AnimatedButton
 public AnimatedButton(Image iv[],
                       String label)
Create an AnimatedButton with the image array as the animation frames and a text label. Add a text label to the button to be displayed with the graphics. The label is placed below the image by default. The default size of the button is the size of the first image in the animation sequence plus necessary space to hold the text label. If the button is resized to a size other than the default size. The images are scaled to fill the area left over by the label inside the button area.

Parameters:
iv - an array of java.awt.Image for animation frames.
label - a text label to be displayed in the button.
 o AnimatedButton
 public AnimatedButton(Image iv[],
                       String label,
                       int pos)
Create an AnimatedButton with the image array as the animation frames, and a text label with position specification. Add a text label at specified position to the button to be displayed with the graphics. See ImageButton for available position flags.

Parameters:
iv - an array of java.awt.Image for animation frames.
label - a text label to be displayed in the button.
pos - the position of the label inside the button. Use the position flags values.

Methods

 o getImages
 public Image[] getImages()
Get the animation frame images array.

Returns:
animation frames.
 o setImages
 public void setImages(Image iv[])
Set the animation frame images.

 o setDelay
 public synchronized void setDelay(int d)
Set the delay between animation frames in miniseconds. Setting the delay larger will make the animation slower.

Parameters:
d - the delay between animation frames in miniseconds.
 o getDelay
 public int getDelay()
Get the delay value. The delay is the number of miniseconds between frames.

Returns:
current delay value.
 o start
 public void start()
Start the animation sequence. If the mouse pointer is in the button, the animation will loop indefinitely until the mouse exits. Otherwise it will execute one sequence and stop.

 o stop
 public void stop()
Stop the animation. The next call to start() will create a new thread for animation. The current thread is killed after this call.

 o paint
 public synchronized void paint(Graphics g)
Paint AnimatedButton. This function should not be called by the user. It is called automatically by AWT and animation routine.

Parameters:
g - Graphics content of this component.
Overrides:
paint in class ImageButton
 o update
 public void update(Graphics g)
Override the default update to avoid flickering.

Parameters:
g - Graphics content of this component.
Overrides:
update in class Component
 o processMouseEvent
 public void processMouseEvent(MouseEvent e)
Mouse enter event starts an animation sequence. If the mouse pointer stays inside the button, the animation will be played repeatedly. The animation is stopped when the mouse pointer moves out of the button area. Mouse exit event terminates the current animation sequence.

Parameters:
e - event object.
Overrides:
processMouseEvent in class ImageButton
 o run
 public synchronized void run()
Run method of the Runnable interface. This is the animation main loop. The user of AnimatedButton should call start instead of run() directly.


All Packages  Class Hierarchy  This Package  Previous  Next  Index