Image Demo

This section simply display the image demo that means multiple images and its name are based on the frame to a particular location. For displaying images demo first of all you will need multiple images that have to be displayed on the frame. The following

Image Demo

This section simply display the image demo that means multiple images and its name are based on the frame to a particular location. For displaying images demo first of all you will need multiple images that have to be displayed on the frame. The following

Image Demo

Image Demo

     

This section simply display the image demo that means multiple images and its name are based on the frame to a particular location. For displaying images demo first of all you will need multiple images that have to be displayed on the frame. The following program displays the images and its name on the frame by using the Toolkit, getImage(), drawString() and drawImage() methods.

Description of code:

drawImage(Image img, int x, int y, ImageObserver ob):
This method used to draw an image that have to used in it. It takes the following parameters:

    img: This is an image that have to be drown.
  x: This is the x coordinate.
  y: This is the y coordinate.
   ob: This is an object that have to be notified as more of the image is converted.

Here is the code of program:

import java.awt.*;
import java.awt.event.*;

public class ImageDemo extends Frame{
  Image image;
  public static void main(String[] args) {
  new ImageDemo();
  }
  public ImageDemo(){
  setTitle("Image Demo Example!");
  setSize(300,200);
  addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent we){
  System.exit(0);
  }
  });
  setVisible(true);
  }
  public void paint(Graphics g){
  Toolkit tool = Toolkit.getDefaultToolkit();
  image = tool.getImage("bt_home.gif");
  g.drawString("Image 1:",20,40);
  g.drawImage(image,20,45,this);
  image = tool.getImage("icon_mini_search.gif");
  g.drawString("Image 2:",20,80);
  g.drawImage(image,20,90,this);
  image = tool.getImage("apache_pb2_ani.gif");
  g.drawString("Image 3:",20,130);
  g.drawImage(image,20,150,this);
  }
}

Download this example.

Output of Program: