by Dinesh Thakur

Usually java.awt.Image class can be used to display GIF (Graphics Interchange Format) or JPEG (Joint Photographic Experts Group.) One way to get a image is using the getImage method available in the Toolkit object that encapsulates  specific methods of the platform used, as below:

Yet this class introduces some methods of interest, as listed below:

Method

Description

flush ()

Releases all resources used by a picture.

getGraphics ()

obtained a graphic context for off-screen rendering.

getHeight (ImageObserver)

obtained the image height is known.

getWidth (ImageObserver)

obtained the width of the image is known.

import java.awt.*;

import java.applet.*;
public class JavaExampleImageUseInApplet extends Applet
{
    Image img;
    public void init()
    {
        img = getImage(getDocumentBase(),"Koala.jpg");
    }
        public void paint(Graphics gr)
         {
           gr.drawImage(img,45,15,this);
         }
}
/*<APPLET CODE=JavaExampleImageUseInApplet.class WIDTH=520 HEIGHT=170 ></APPLET>*/

Image Use in Applet Java Example