Loading pictures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rengaraj
    New Member
    • Jan 2007
    • 168

    Loading pictures

    hi everyone

    how can i load a picture which i want to use in my program?
    actually i have wore this code below but i guess the problem is i
    dont know how to add the BufferedImage to the Frame, i will be
    grateful if u help me

    regards
    razieh

    import java.awt.image. BufferedImage;
    import java.io.File;
    import java.io.IOExcep tion;
    import javax.imageio.I mageIO;
    import javax.swing.JFr ame;

    public class Target extends JFrame
    {

    BufferedImage img;

    public Target()
    {
    try
    {
    img = ImageIO.read(ne w File ("C:\\Target.jp g"));
    setDefaultClose Operation (EXIT_ON_CLOSE) ;
    setVisible (true);
    setSize(500,500 );

    }
    catch(IOExcepti on e)
    {
    System.out.prin tln("file does not exist");
    }
    }
    public static void main(String []args)
    {
    new Target();

    }
    }//end of class
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Where on the frame do you want to add it? One option is to have a JLabel and set it's Icon to be that image.

    Comment

    Working...