Saturday, 17 August 2013

How to open an image using Imageicon on a jframe

How to open an image using Imageicon on a jframe

I am trying to simply draw an image on a jframe by using an Imageicon.
However when I run it its just blank. Heres my code...
public final class PICS
{
public static final void main(String... aArgs)
{
JFrame frame = new JFrame("IMAGE");
frame.setVisible(true);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image = new ImageIcon("image/pic1.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
}
}
I am very new to everything java including this website, so I apologize if
im missing something. Also im using Eclipse, and are there specific
formats you can use for images, or is there a limit to size?

No comments:

Post a Comment