§ blocked - a thread is said to be blocked when it is waiting for an event, such as an input / output operation. § dead – the thread is dead after the run() method has completed execution or its stop() method has been called.
import java.util.*;
import java.awt.*;
import java.applet.*;
public class Javase_68 extends Applet implements Runnable
{
Thread thrpic=null;
Image[] frame=new Image[10];
int frame_i=0,delay_time;
public void init()
{
int i;
String fps;
for(i=0;i<frame.length;i++) //加载图像到数组中
frame[i]=getImage(getDocumentBase(),"image/picture"+i+".gif");
fps=getParameter("frame_per_second");
if(fps==null) fps="10";
delay_time=1000/Integer.parseInt(fps); //设置两张图处理相隔的时间
}
public void paint(Graphics g)
{
g.drawImage(frame[frame_i],0,0,this);
}
public void start()
{
if(thrpic==null)
{
thrpic=new Thread(this);
thrpic.start();
}
}
public void stop()
{
thrpic.interrupt();
thrpic=null;
}
public void run()
{
while(true)
{
try { Thread.sleep(delay_time); }
catch (InterruptedException e) { }
repaint();
frame_i=(frame_i+1)%frame.length;
}
}
}