Home Java Example Java Awt Image Demo

Related Tutorials


 
 

Share on Google+Share on Google+

Image Demo

Advertisement
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:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 13, 2008

Related Tutorials

Discuss: Image Demo   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com