import java.applet.*;
import java.awt.*;

        // Retrieve an image file from the same location as the
        // originating HTML file (the Document Base).
public class AppleApplet extends Applet {
    public void init() throws RuntimeException {
        // Get the apple image.
        setImage(retrieveImage("apple.gif"));
    }

        // Scale the image to the full size of the applet.
    public void paint(Graphics g){
        final Dimension size = getSize();
        Image image = getImage();
        if(image != null){
            g.drawImage(image,0,0,size.width,size.height,this);
        }
    }

        // Get the image, which is located in fileName relative
        // to the document which loaded this applet.
    protected Image retrieveImage(String fileName) throws RuntimeException {
        Image appleImage = getImage(getDocumentBase(),fileName);
        // Wait for it to load.
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(appleImage,0);
        try{
            tracker.waitForAll();
        }
        catch(InterruptedException e){
        }
        // Make sure loading was successful.
        if(tracker.isErrorAny()){
            throw new RuntimeException("Image loading problem: "+fileName);
        }
        else{
            return appleImage;
        }
    }

    protected Image getImage(){
        return image;
    }

    protected void setImage(Image i){
        image = i;
    }

    // The image to be displayed in the full size of the applet.
    private Image image;
}
