Java Reference
In-Depth Information
private int
numFrames; //(No longer a constant.)
private int oldNumFrames; //No. of frames in
//previous image.
private int currentImage = 0;
private int
delay
= 100;
//(No longer a constant.)
private Timer animTimer;
public static void main(String[] args)
{
AnimBean
2
anim = new AnimBean
2
();
anim.setVisible(true);
}
public AnimBean
2
()
{
//Loading of frames not done just once now,
//so must be moved out of constructor…
loadFrames();
animTimer = new Timer(delay,this);
animTimer.start();
}
private void loadFrames()
{
//Check no. of frames in animation fi rst…
numFrames = 0;
File fi leName =
new File(imageName + numFrames + ".gif");
while (fi leName.exists())
{
//Increment frame count for each image in
//sequence that is found…
numFrames++;
//Update fi lename to check for next frame in
//sequence…
fi leName =
new File(imageName + numFrames + ".gif");
}
if (numFrames==0) //No image found!
return; //Abandon loading of frames.
//Following lines moved from constructor
//(with no. of frames now variable)…
image = new ImageIcon[numFrames];
//Now load frames…
Search WWH ::
Custom Search