Java Reference
In-Depth Information
for (int i=0; i< numFrames ; i++)
{
image[i] =
new ImageIcon(imageName + i + ".gif");
}
}
public void paint(Graphics g)
{
//Check whether user has changed
// imageName property…
if (!imageName.equals(oldImage))
{
//Load new frame sequence…
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;
//Retrieve background colour…
g.setColor(getBackground());
//Erase old image by fi lling old image area
//with background colour…
g.fi llRect(0,0,getWidth(),getHeight());
//Reset frame count to fi rst frame in new
//sequence…
currentImage = 0;
}
}
if (numFrames>0)
{
image[currentImage].paintIcon(this,g,0,0);
currentImage = (currentImage+1)%numFrames;
}
}
Search WWH ::




Custom Search