Home Java Example Java Awt Image Demo



Image Demo
Posted on: March 13, 2008 at 12:00 AM
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 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:

Related Tags for Image Demo:
cstringimageimagesiomethodsmultiplemethodsedgetdisplayipnameusingthislocationtoolootoolkitframeforprogramtodrawrambaserawwseilitmultisectiondemosplulimfirstartdrawstringinpartasmplaypartrtimagecaispbasedeswstringemdrawimageaseallageiculocmemeanprocatstipspeedisplayingdisplaysatplyplayingkisirhallkitmplfolloweaandarstrrtsimwingssriringrawstringthavstatihatdispframmageiplisplayingpleplprndodsonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Image Demo   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.