Java applet program to display image

This applet program displays an image on the applet viewer. The program declares an object of the Image class. Then the program calls the getImage() function to specify the image and drawImage() function to draw the image to the output screen. The image to be displayed must be stored in the same directory where the source code is stored. 


Program



//Applet program to display image

//<Applet code=ImageApplet height=400 width=400></Applet>

import java.awt.*;

import java.applet.*;

public class ImageApplet extends Applet

{

Image img;

public void paint(Graphics g)

{

img=getImage(getCodeBase(),"lotus.jpg");

g.drawImage(img,100,100,this);

}

}


Output


image applet in java
Applet program to display image

No comments: