转贴import java.awt.*;
import java.applet.*;public class Test extends Applet {
    ImageCanvas ip;    public void init() {
        Image i = getImage(getDocumentBase(), "on.gif");
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(i, 0);
        try { tracker.waitForAll(); } catch (InterruptedException e) { ; }
        ip = new ImageCanvas(i);
        setLayout(new BorderLayout(10,10));
        add("Center", ip);
    }
}class ImageCanvas extends Canvas {
    Image image;    public ImageCanvas(Image i) {
        super();
        image = i;
    }    public void paint(Graphics g) {
        g.drawImage(image, image.getWidth(this) >> 1,
                    image.getHeight(this) >> 1, this);
    }
}
//  ImageObserver exampleimport java.awt.*;
import java.awt.image.*;
import java.applet.Applet;public class Test extends Applet implements ImageObserver {
    Image       img;
    int         width, height;
    boolean image_ready = false;    public void init() {
        image_ready = false;
        img = getImage(getDocumentBase(),"on.gif");
        img.getWidth(this);
        img.getHeight(this);
        prepareImage(img, this);
    }    public boolean imageUpdate(Image img,int status, int x,
                           int y, int width, int height){
        if ((status & HEIGHT) != 1) {
            this.height = height;
        }
        if ((status & WIDTH) != 1) {
            this.width = width;
        }
        if ((status & ALLBITS) != 1) {
            image_ready = true;
            repaint();
            return true;
        }
        return false;
    }    public void paint(Graphics g) {
        if (image_ready)
            g.drawImage(img, width >> 1, height >> 1,this);
    }