by Dinesh Thakur

 The Image class is used to load and display images. To load an image the getimage ()method of the Image class is used and to display the image the draw Image ()method of the Graphics class is used.

The general form of the getImage () method is

Image getimage(URL pathname, String filename)

Image getimage(URL pathname)


pathname is the address of the image file on web. When the image file and the source file are in the same directory, getCodeBase ()method is used as first parameter to the method.

filename is the name of the image file

The general form of the drawimage ()method is

boolean drawimage(Image image, int startx, int starty,

int width, int height, ImageObserver img_obj)


image is the image to be loaded in the applet.

startx is the pixels space from the left comer of the screen.

starty is the pixels space from the upper comer of the screen.

width is the width of the image.

height is the height of the image.

img_obj is object of the class that implements ImageObserver interface.

import java.awt.*;

import java.applet.*;
/*<APPLET CODE=JavaExampleIObserverInApplet.class WIDTH=610 HEIGHT=160></APPLET>*/
public class JavaExampleIObserverInApplet extends Applet
    Image img;
    public void init()
        img = getImage(getDocumentBase(),"Koala.jpg");
        public void paint(Graphics gr)
           public boolean imageUpdate(Image img1,int flags, int xAxis, int yAxis, int width, int height)
            if ((flags & ALLBITS) != 0)
                  return (flags & ALLBITS) == 0;

Draw Image and ImageObserver in Java Applet