Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Get Image

Advertisement
This Example shows you get the image.

Get Image

     

This Example shows you get the image.

Description of the code :

Toolkit.getDefaultToolkit() : Toolkit class is used to bind the different components to specific native toolkit implementations. if we want to implementation Toolkit then firstly set System property named "java.awt.headless" is set to true.getDefaultToolkit is used for get the default toolkit.

Toolkit.getImage() : getImage method return a Image class object and this object get pixel data from the specified URL.

Graphics.drawImage() : drawImage method is used to draw a specified image as is currently available. The image is drawn with its top-left corner at (x, y) coordinate.

Graphics.drawString() : drawImage method is used for draw a specified String. Its top-left corner at (x, y) coordinate.

Frame.setSize () : setSize method is used for set the frame size.

Frame.setVisible() : setVisile method is used for visible true or false.

GetImage.java

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

public class GetImage extends Frame {

  Image image;
  String imageName = "javalogo.png";

  public GetImage() {

  addWindowListener(new WindowAdapter() {

  public void windowClosing(WindowEvent we) {
  System.exit(0);
  }
  });
  }

  public void paint(Graphics g) {

  Toolkit tool = Toolkit.getDefaultToolkit();
  image = tool.getImage(imageName);
  g.drawImage(image, 1030this);
  g.drawString(imageName, 17050);
  }

  public static void main(String args[]) throws Exception {

  GetImage image = new GetImage();
  image.setSize(400340);
  image.setVisible(true);
  image.setLocation(200100);
  }
}

Output




Download code

 

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: October 23, 2008

Related Tutorials

Ask Questions?    Discuss: Get Image   View All Comments

Post your Comment


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