2010-12-02 5 views
-1

버튼이 포함 된 JFrame/패널 작업 중입니다. 사용자가 버튼을 클릭하면 컴퓨터 하드 디스크에 미리 저장 될 이미지가 전면 스크린에서 열리겠습니다.자바를 사용하여 .bmp/​​.jpeg 이미지를 여는 방법

button.addActionListener(new ActionListener(){ 
     public void actionPerformed(ActionEvent e){ 
     //here i want a code that will somehow open the image from a given directory 
      }}); 

이 문제를 해결하는 방법에 대한 제안 사항이 있으십니까? 이미지가 저장된 위치를 말하고 이미지가 전면 스크린에 팝업되도록 가상의 '더블 클릭'을 트리거해야합니다. 그러한 컴퓨터 기능을 동기화하기 위해 자바를 사용하는 것이 가능합니까?

+0

이 게시물은 http://stackoverflow.com/questions/526037/java-how-to-open-user-system-preffered-editor-for-given-file 이후에있는 것으로 보입니다. – Karl

답변

3

나는 매우 짧은 방법을 잘 모르겠지만, (인상을 얻기 위해 해킹 qick로) 나는이 같은 것을 사용하는 것이 :

try { 
    // this is a new frame, where the picture should be shown 
    final JFrame showPictureFrame = new JFrame("Title"); 
    // we will put the picture into this label 
    JLabel pictureLabel = new JLabel(); 

    /* The following will read the image */ 
    // you should get your picture-path in another way. e.g. with a 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 the image as ImageIcon to the label 
    pictureLabel.setIcon(new ImageIcon(img)); 
    // add the label to the frame 
    showPictureFrame.add(pictureLabel); 
    // pack everything (does many stuff. e.g. resizes the frame to fit the image) 
    showPictureFrame.pack(); 

    //this is how you should open a new Frame or Dialog, but only using showPictureFrame.setVisible(true); would also work. 
    java.awt.EventQueue.invokeLater(new Runnable() { 

     public void run() { 
     showPictureFrame.setVisible(true); 
     } 
    }); 

    } catch (IOException ex) { 
    System.err.println("Some IOException accured (did you set the right path?): "); 
    System.err.println(ex.getMessage()); 
    } 
나는이 일을 생각
0

...

코드 :

process = new ProcessBuilder ("mspaint", "yourFileName.jpeg"). start();

이 MSPAINT와 이미지 파일을 엽니 다 .....

도 사용 * 자바 고급 이미징 (JAI) *

0

이 코드

try 
{ 
    // the line that reads the image file 
    BufferedImage image; 


    // work with the image here ... 
     image = ImageIO.read(new File("C://Users//Neo//Desktop//arduino.jpg")); 


     jLabel1.setIcon(new ImageIcon(image)); 
} 
catch (IOException e) 
{ 
    // log the exception 
    // re-throw if desired 
} 
0

에게 시도 확실하지는 않지만 다음을 시도하십시오.

try 
{ 

    JLabel picture=new JLabel(); 

    ImageIcon ic=new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("C:\\Users\\Desktop\\xyz.jpg"))); 

    picture.setIcon(ic); 

} 
catch(Exception) 
{ 
} 
관련 문제