Java Reference
In-Depth Information
image[i] =
new ImageIcon(imageName + (i+1) + ".gif");
}
}
public void startAnimation()
{
if (animTimer == null)
{
currentImage = 0;
animTimer = new Timer(delay,this);
animTimer.start();
}
else
if (!animTimer.isRunning())
animTimer.restart();
}
public void stopAnimation()
{
animTimer.stop();
}
public void paint(Graphics g)
{
if (!imageName.equals(oldImage))
{
loadFrames();
if (numFrames==0) //No image found!
{
//Reset image name and no. of
//frames to their old values…
setImageName(oldImage);
numFrames = oldNumFrames;
}
else
{
oldImage = imageName;
oldNumFrames = numFrames;
g.setColor(getBackground());
g.fi llRect(0,0,getWidth(),getHeight());
currentImage = 0;
}
}
if (numFrames>0) //Image exists.
{
image[currentImage].paintIcon(this,g,0,0);
currentImage = (currentImage+1)%numFrames;
Search WWH ::




Custom Search