package Applet包;
import java.applet.Applet;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Graphics;
public class TestImage extends Applet {
private Image[] imgs;
private int totalImages=10;
private int currentImage;
public void init(){
imgs =new Image[totalImages];
for(int i=0;i<totalImages;i++)
{
imgs[i]=getImage(getDocumentBase(),"T"+(i+1)+".gif");
}
//img=getImage(getDocumentBase(),"T1.gif");
}
public void start()
{
currentImage=0;
}
public void paint(Graphics g){
//g.drawImage(img,0,0,this);
g.drawImage(imgs[currentImage],0,0,this);
currentImage=++currentImage%10;
try{
Thread.sleep(500);
}
catch(Exception ex){
ex.printStackTrace();
}
repaint(); //调用repaint()方法时,会产生awt现成;
//awt现成会调用update()方法,由update方法调用paint()方法。
}
} |