by Dinesh Thakur Category: AWT and Applets

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:



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)
/*<APPLET CODE=JavaExampleImageUseInApplet.class WIDTH=520 HEIGHT=170 ></APPLET>*/

Image Use in Applet Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles