Display image in the applet

This program illustrates you to display image in an applet which has been done in this example.

Display image in the applet



This program illustrates you to display image in an applet which has been done in this example. In this program you will see that how many methods, classes, packages and it's properties have been used to display the image in an applet.

In this program only one function paint(Graphics g) has used. Function paint(Graphics g) is also a part of the life cycle of an applet in which anything you can draw in your applet to appear on the browser. In this function MediaTracker class of the java.awt.*; package, has been used. MediaTracker is a utility class that tracks the status of a number of media objects. And this type of object can include images and audio clips. In this program only the explanation about the adding images has been given. MediaTracker class is used after creating the instance for that and calling the addImage() of the MediaTracker class which is used in this program as you can see. In this program method getImage() is used to return the image for the object ( img ) of the Image class taking two arguments, first is getCodeBase() and another is image name. Then the addImage() method of the MediaTracker has been used. Syntax of the addImage() function is MediaTracker.addImage(img, x, y, x1, y1). Arguments of addImage() function is explained below : 

img - image name type of Image.
x   - lower X - Coordinate type of int.
y   - lower Y - Coordinate type of int.
x1   - upper X - Coordinate type of int.
y1   - upper Y - Coordinate type of int.

Here is the code of the program : 

import java.applet.*; 
import java.awt.*; 
public class appletImage extends Applet{
  Image img;
  MediaTracker tr;
  public void paint(Graphics g) {
  tr = new MediaTracker(this);
  img = getImage(getCodeBase()"freelinuxcds.gif");
  g.drawImage(img, 00this);

Try online this example.

Download this example.

Share on Google+Share on Google+

Display image in the applet

Posted on: April 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Display image in the applet   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
munde manojkumar
October 2, 2011
display image or play songs on applet in java

please give me program
shweta gupta
November 17, 2011
java programming

i want do a programming of java applet, i search it, nd finally i done it thanku..........
January 27, 2012
Fetch image

how i can show image on window browser from any device . how to give path for that image
September 14, 2012
Add Image in Applet

How can i add image from my pc/laptop? where i am write a address of image..?
September 21, 2012

nice example its help me alottt
November 1, 2012
Save button

HI, in my project I am using applet and want to save image(.jpg)file format.but file will saved applet.ser format. Can any Body help me how can I do it Thanks & Regards Stalin
October 24, 2013

i want display image into java eclipse ide plz help me