能运行,但为什么我的程序不能显示图片?
import java.applet.Applet;
import java.awt.*;public class Imager extends Applet
{
    Image picture;     boolean imageLoaded = false;    public void init()
    {
        picture = getImage(getCodeBase(), "llk.gif"); // 装载图像
        Image offScreenImage = createImage(this.getSize().width,
        this.getSize().height);
        Graphics offScreenGC = offScreenImage.getGraphics(); // 获取Graphics对象
        offScreenGC.drawImage(picture, 0, 0, this); // 显示非屏幕图像
    }    public void paint(Graphics g)
    {
        if (imageLoaded)
        {
            g.drawImage(picture, 0, 0, null); // 显示图像,第四参数为null,不是this
            showStatus("Done");
        } else
            showStatus("Loading image");
    }    public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
            int h)
    {
        if (infoflags == ALLBITS)
        {
            imageLoaded = true;
            repaint();
            return false;
        } else
            return true;
    }
}

解决方案 »

  1.   

    刚才运行了一下你的程序,没问题,可以正常显示图片,我是在eclipse下运行的,你不能显示图片有两种可能:
    1、图片过大,加载太慢、或者图片的格式不支持
    2、可能你的图片存放在了错误的位置,一开始我是放在和源程序的同一个包下,这样,程序反而不能显示图片,改到他的上一级,java项目名下就可以了
    不知道你是不是明白?