用命令jar cvf imagetest.jar imagetest T*.gif,将JAVA包imagetest以及图片T*.gif一起打包为imagetest.jar。其中,文件夹imagetest中
包含MultiThread.class。但是,打开HTML文件multi.html时,总是说加载JAVA小程序失败。大家看看是怎么回事啊?都有什么可能会原因会引
起这样的情况啊?源代码如下:
//MultiThread.java
package imagetest;
import java.applet.*;
import java.awt.*;
import java.lang.Runnable;
public class MultiThread extends Applet implements Runnable
{
private Image ma[];
private int total=10;
private int current;
private int i=0;
private Image imagebuffer;
private Graphics ghbuffer;
private MediaTracker mt;
private boolean bstop=false;
public void init()
{
mt=new MediaTracker(this);
imagebuffer=createImage(600,400);
ghbuffer=imagebuffer.getGraphics();
ghbuffer.setColor(Color.WHITE);
ghbuffer.fillRect(0,0,600,400);
ma=new Image[total];
for(int i=0;i<total;i++)
{
ma[i]=getImage(getDocumentBase(),"T"+(i+1)+".gif");
mt.addImage(ma[i],i);
}
try
{
mt.waitForID(0);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void start()
{
current=0;
ghbuffer.drawImage(ma[current],0,0,this);
current=1;
new Thread(this).start();
}
public void stop()
{
bstop=true;
}
public void paint(Graphics g)
{
g.drawImage(imagebuffer, 0, 0, this);
}
public void update(Graphics g)
{
paint(g);
}
public void run()
{
while(!bstop)
{
if(mt.checkID(current,true))
{
System.out.println(i++);
ghbuffer.fillRect(0, 0, 600, 400);
ghbuffer.drawImage(ma[current], 0, 0, this);
current = ++current % 10;
}
try
{
Thread.sleep(300);
}
catch (Exception ex)
{
ex.printStackTrace();
}
repaint();
}
}
}
//multi.html
<applet code="imagetest.MultiThread.java" width=600 height=400 archive="imagetest.jar">
</applet>