Searching...
Thursday, March 27, 2014

Set image in your java code

1:17 PM

You can view your image file from your disk using java programming.The code is given bellow
/*Code start*/
package jframe_practise; import javax.imageio.ImageIO; import javax.swing.*; //import javax.imageio.*; import java.awt.*; import java.io.File; import java.io.IOError; public class photo_open { public static void main(String[] args) { JFrame j=new JFrame("hi i am mohon"); try{ j.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("E:\\PHOTO\\IMG_20131123_123500.jpg"))))); }catch(Exception e){ System.out.println("image doesnot exist"); } j.setVisible(false); j.pack(); j.setVisible(true); } }

//EOF

N.B:Change your image location with E:\\PHOTO\\IMG_20131123_123500.jpg.

0 comments:

Post a Comment

Followers