Home Java Example Java Awt Paint an Image



Paint an Image
Posted on: March 14, 2008 at 12:00 AM
This section provides you to paint an image on the frame. Paint means draw an image and set its on the frame to the specified location according to its x coordinate and y coordinate.

Paint an Image

     

This section provides you to paint an image on the frame. Paint means draw an image and set its on the frame to the specified location according to its x coordinate and y coordinate.

Description of program:

In this program you will see how to paint an image on the fame to specified location. For this you need images that have to be set on the frame. Here first of all draw a rectangle and set the two images on to rectangle. Paint the rectangle in the yellow color. All drawing process is done using the paint() method. 

Here is the code of program:

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

public class PaintIcon extends Frame{
  Image image;
  public static void main(String[] args) {
  new PaintIcon();
  }
  public PaintIcon(){
  setTitle("Paint an Icon example!");
  setSize(200,200);
  setVisible(true);
  addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent we){
  System.exit(0);
  }
  });
  }
  public void paint(Graphics g){
  Toolkit tool = Toolkit.getDefaultToolkit();
  image = tool.getImage("warning.gif");
  g.drawRect(20,50,100,100);
  g.drawString("Draw Images:",20,40);
  g.setColor(Color.yellow);
  g.fillRect(20,50,100,100);
  g.drawImage(image,30,85,this);
  image = tool.getImage("Tom.gif");
  g.drawImage(image,80,85,this);
  
  }
}

Download this example.

Output of program:

Related Tags for Paint an Image:
cimageideimagesprocessscriptiodrawingmethodcoloripviusingintthisidlocationaisetooframeifforiepaintprogramnattorectangledrawramrawciangleprocdescriptioneilitdessectionpeimfirstceinmntcaesspecallagelocmemeanhowprocatdosrectspeeesscolatisirhallpaineaandccwingtwscrssrocririprdthavstatihatfameframmageprocesprndonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Paint an Image  

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.