importjava.awt.*;importjavax.swing.*;publicclassPictureAnimationextendsJAppletimplementsRunnable{finalintIMG_COUNT=4;ImageIconimg[];JLabellabelPic;intnumber=0;Threadanima...
import java.awt.*;
import javax.swing.*;
public class PictureAnimation extends JApplet implements Runnable{
final int IMG_COUNT=4;
ImageIcon img[];
JLabel labelPic;
int number=0;
Thread animationThread;
public void init(){
this.setSize(500,500);
img=new ImageIcon[IMG_COUNT];
for(int i=0;i
img[i]=new ImageIcon(getImage(getDocumentBase(),"image/"+i+".jpg"));
labelPic=new JLabel("");
getContentPane().add(labelPic);
animationThread=new Thread(this);
animationThread.start();
}
public void run()
{
while(animationThread!=null)
{
labelPic.setIcon(img[number]);
number++;
if(number==IMG_COUNT)
number=0;
try
{
animationThread.sleep(2000);
}
catch(InterruptedException e){}
}
}
}
展开