import java.awt.*;
import java.applet.*;
//Download by http://www.codesc.net
public class useTrackedImage extends Applet implements Runnable
{
private Image picture;
private MediaTracker tracker;
//初始化
public void init()
{
this.picture = this.getImage(this.getCodeBase(),
//获取图片信息
this.getParameter("imagefile"));
this.tracker = new MediaTracker(this);
//加载图片
this.tracker.addImage(this.picture, 1);
Thread play = new Thread(this);
//启动线程
play.start();
}
//执行线程
public void run()
{
try
{
this.tracker.waitForID(1);
//刷新界面
this.repaint();
}
catch (InterruptedException ie)
{ }
}
//绘制图片
public void paint(Graphics g)
{
if (this.tracker.checkID(1, true))
{
g.drawImage(this.picture, 0, 0, this);
}
else
{
g.drawString("Loading Picture. Please hang on", 25, 50);
}
}
}