public class AnimatedImage
extends java.awt.image.BufferedImage
implements java.awt.event.ActionListener
TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE, TYPE_BYTE_BINARY, TYPE_BYTE_GRAY, TYPE_BYTE_INDEXED, TYPE_CUSTOM, TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_BGR, TYPE_INT_RGB, TYPE_USHORT_555_RGB, TYPE_USHORT_565_RGB, TYPE_USHORT_GRAY
Constructor and Description |
---|
AnimatedImage(javax.swing.JComponent component,
java.awt.Image... images)
Create an AnimatedImage that will continuously cycle with the
default (500ms).
|
AnimatedImage(javax.swing.JComponent component,
int delay,
java.awt.Image... images)
Create an AnimatedImage that will continuously cycle with the specified
delay
|
AnimatedImage(javax.swing.JComponent component,
int delay,
int cycles,
java.awt.Image... images)
Create an AnimatedImage specifying the required delay between painting
each image and the number of times to repeat the animation sequence
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Controls the image animation that is scheduled by the Timer
|
void |
addImage(java.awt.Image image)
Add Image to be used in the animation.
|
int |
getCurrentImageIndex()
Get the index of the currently visible Image
|
int |
getDelay()
Returns the delay between painting each Image
|
int |
getHeight(java.awt.image.ImageObserver obs)
Gets the height of this image.
|
java.awt.Image |
getImage(int index)
Returns the Image at the specified index.
|
int |
getImagesCount()
Returns the number of Images that are contained in the animation
|
protected int |
getNextImageIndex(int currentIndex,
int imageCount)
Gets the index of the next Image to be displayed.
|
int |
getRemainingCycles()
Get the remaining cycles to complete before the animation stops.
|
int |
getWidth(java.awt.image.ImageObserver obs)
Gets the width of this image.
|
protected boolean |
isCycleCompleted(int currentIndex,
int imageCount)
Checks if the currently displayed Image is the last image of the
animation sequence.
|
boolean |
isShowFirstImage()
Get the showFirstImage
|
void |
pause()
Pauses the animation.
|
void |
restart()
Restarts the animation from where the animation was paused.
|
void |
setCurrentImageIndex(int index)
Set the index of the Image to be displayed and then repaint the Image.
|
void |
setCycles(int cycles)
Specify the number of times to repeat each animation sequence, or cycle.
|
void |
setDelay(int delay)
Specify the delay between painting each Image
|
void |
setShowFirstImage(boolean showFirstImage)
Displays the first image of the animation after the last cycle has passed
If set to false, the last image will remain set after the last
animation cycle.
|
void |
start()
Start the animation from the beginning.
|
void |
stop()
Stops the animation.
|
addTileObserver, coerceData, copyData, createGraphics, getAlphaRaster, getColorModel, getData, getData, getGraphics, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getProperty, getPropertyNames, getRaster, getRGB, getRGB, getSampleModel, getSource, getSources, getSubimage, getTile, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getTransparency, getType, getWidth, getWritableTile, getWritableTileIndices, hasTileWriters, isAlphaPremultiplied, isTileWritable, releaseWritableTile, removeTileObserver, setData, setRGB, setRGB, toString
public AnimatedImage(javax.swing.JComponent component, java.awt.Image... images)
component
- the component the image will be painted onimages
- the Images to be painted as part of the animationpublic AnimatedImage(javax.swing.JComponent component, int delay, java.awt.Image... images)
component
- the component the image will be painted ondelay
- the delay between painting each image, in milli secondsimages
- the Images to be painted as part of the animationpublic AnimatedImage(javax.swing.JComponent component, int delay, int cycles, java.awt.Image... images)
component
- the component the image will be painted ondelay
- the delay between painting each image, in milli secondscycles
- the number of times to repeat the animation sequenceimages
- the Images to be painted as part of the animationpublic void addImage(java.awt.Image image)
image
- the image to be addedpublic int getCurrentImageIndex()
public void setCurrentImageIndex(int index)
index
- the index of the Image to be displayedpublic int getRemainingCycles()
public void setCycles(int cycles)
cycles
- the number of cycles to complete before the animation
stops. The default is -1, which means the animation is
continuous.public int getDelay()
public void setDelay(int delay)
delay
- the delay between painting each Image (in milli seconds)public java.awt.Image getImage(int index)
index
- the index of the Image to be returnedjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic int getImagesCount()
public boolean isShowFirstImage()
public void setShowFirstImage(boolean showFirstImage)
showFirstImage
- true when the first image is to be displayed,
false otherwisepublic void pause()
public void start()
public void restart()
public void stop()
public int getWidth(java.awt.image.ImageObserver obs)
getWidth
in class java.awt.image.BufferedImage
public int getHeight(java.awt.image.ImageObserver obs)
getHeight
in class java.awt.image.BufferedImage
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
protected int getNextImageIndex(int currentIndex, int imageCount)
currentIndex
- the index of the Image currently displayedimageCount
- the number of Images to be displayedprotected boolean isCycleCompleted(int currentIndex, int imageCount)
currentIndex
- the index of the Image currently displayedimageCount
- the number of Images to be displayed
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.