Java Reference
In-Depth Information
each image in the sequence. Appended to this will be
an integer in the range 0-3, followed by the suffi x
'.gif' (so names will be 'juggler0.gif', …,
'juggler3.gif').
*/
private fi nal int NUM_FRAMES = 4;
private int currentImage = 0;
//Holds no. of current frame.
private fi nal int DELAY = 100; //100/1000sec = 0.1sec
//(May need to be adjusted for different processors.)
private Timer animTimer;
public static void main(String[] args)
{
AnimBean1 animation = new AnimBean1();
//If panel size is set here, it is ignored!
animation.setVisible(true);
}
public AnimBean1()
{
//Set up array of images…
image = new ImageIcon[NUM_FRAMES];
for (int i=0; i<image.length; i++)
{
image[i] =
new ImageIcon(imageName + i + ".gif");
}
animTimer = new Timer(DELAY,this);
//Call inbuilt method start of Timer object…
animTimer.start();
}
public void paint(Graphics g)
{
//Display next frame in sequence…
image[currentImage].paintIcon(this,g,0,0);
//Update number of frame to be displayed, in
//preparation for next call of this method…
currentImage = (currentImage+1)%NUM_FRAMES;
}
Search WWH ::




Custom Search