Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/articles/java-tutorials/)
-   -   Putting an Image on your Java applications. (http://www.go4expert.com/articles/putting-image-java-applications-t8197/)

Systemerror 11Jan2008 15:41

Putting an Image on your Java applications.
 
I often hear people asking on how to put an image on Java applications, thus here is an example of a painted panel that has an image in the same directory as the application *note* you cant use windows bmp with Java, but once you start creating your own images it's a good time to note that their are many "free image converters" available.

Code: Java

import java.awt.*;
import javax.swing.*;

public class PaintPanel extends JFrame
{
 
 public PaintPanel()
 {
  super("painted panel example");
  setSize(640, 400);
  setResizable(false);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);                              //create frame

  Container contentArea = getContentPane();      //create container

  CustomPanel panel = new CustomPanel();
  contentArea.add(panel);
  setContentPane(contentArea);                   //add components
 }

  class CustomPanel extends JPanel
  {
   public void paintComponent (Graphics painter)
   {

    Image pic =
          Toolkit.getDefaultToolkit().getImage("gui1.gif");
   if(pic != null) painter.drawImage(pic, 15, 5, this);     //create image
 
  }
}
 
  public static void main(String [] args)
  {PaintPanel eg = new PaintPanel();}
}


Hope i've helped.

shabbir 3Feb2008 12:32

Re: Putting an Image on your Java applications.
 
Nominate this article for the month for January 2007

shabbir 19Feb2008 12:45

Re: Putting an Image on your Java applications.
 
Voting for article of the month for January 2008

imrantechi 20Feb2008 11:10

Re: Putting an Image on your Java applications.
 
nice one

imrantechi 20Feb2008 11:12

Re: Putting an Image on your Java applications.
 
i m new to java ,when i try this program it gives some errors ---exception handle what is this

debleena_doll2002 20Feb2008 11:34

Re: Putting an Image on your Java applications.
 
Have you tried for run this program. It's not working in my system. May be some problem in my system

debleena_doll2002 20Feb2008 11:48

Re: Putting an Image on your Java applications.
 
Have you tried for run this program. It's not working in my system. May be some problem in my system

elec.shabnam 20Feb2008 12:21

Re: Putting an Image on your Java applications.
 
its not working, exceptions are there

elec.shabnam 20Feb2008 12:22

Re: Putting an Image on your Java applications.
 
can you please recheck it and post it back again

elec.shabnam 20Feb2008 12:22

Re: Putting an Image on your Java applications.
 
i really need this , i want to learn java


All times are GMT +5.5. The time now is 22:51.