当前位置: 代码迷 >> Java相关 >> 怎么没有显示图像?
  详细解决方案

怎么没有显示图像?

热度:270   发布时间:2006-05-19 15:47:00.0
怎么没有显示图像?

下面是java源代码:
/*
<applet code="Animate.class" width=300 height=300>
</applet>
*/
import java.awt.*;
import java.applet.Applet;
public class Animate extends Applet
{
private static int NIMAGES=5;
private static int MILLISECS=200;
private Image image[]=new Image[NIMAGES];
private int imageN=0;
public void init()
{
showStatus("Loading image files. please wait");
for(int k=0;k<image.length;k++)
image[k]=getImage(getDocumentBase(),"spider"+k+"gif");
}
public void paint(Graphics g)
{
g.drawImage(image[imageN],20,20,this);
imageN=(imageN+1)%NIMAGES;
delay(MILLISECS);
repaint();
}
private void delay(int n)
{
try
{
Thread.sleep(n);
}
catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
}
我把图像文件放在和源文件一个目录下,启动后没有什么显示?

搜索更多相关的解决方案: 图像  

----------------解决方案--------------------------------------------------------
image[k]=getImage(getDocumentBase(),"spider"+k+"gif");//你这里小了一个点"."
还有,如果你的图像文件是和你的HTML文件放在一个目录,上面就是对的
如果有类放在一起的话,就要改为getCodeBase()

----------------解决方案--------------------------------------------------------

还有,不推荐以你那种在paint里面调用repaint方法来画图的方法
你要改变图,可以启动一个线程专门做这个事情,并且又好控制


----------------解决方案--------------------------------------------------------

哦,太谢谢千里哥了!


----------------解决方案--------------------------------------------------------
  相关解决方案