Hows to open an .bmp/.jpeg image using Java -


i working on jframe/panel contain button. when user clicks button, want image (which stored in computer hard disk beforehand) open on front screen.

button.addactionlistener(new actionlistener(){         public void actionperformed(actionevent e){         //here want code somehow open image given directory             }}); 

any suggestions on how go ? have tell image stored , trigger virtual 'double click' image pop on front screen. possible using java synchronize such computer functions?

i don't know short way, use (as qick hack impression):

  try {     // new frame, picture should shown     final jframe showpictureframe = new jframe("title");     // put picture label     jlabel picturelabel = new jlabel();      /* following read image */     // should picture-path in way. e.g. jfilechooser     string path = "c:\\users\\public\\pictures\\sample pictures\\koala.jpg";     url url = new file(path).touri().tourl();     bufferedimage img = imageio.read(url);     /* until here */      // add image imageicon label     picturelabel.seticon(new imageicon(img));     // add label frame     showpictureframe.add(picturelabel);     // pack (does many stuff. e.g. resizes frame fit image)     showpictureframe.pack();      //this how should open new frame or dialog, using showpictureframe.setvisible(true); work.     java.awt.eventqueue.invokelater(new runnable() {        public void run() {         showpictureframe.setvisible(true);       }     });    } catch (ioexception ex) {     system.err.println("some ioexception accured (did set right path?): ");     system.err.println(ex.getmessage());   } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -