import javax.swing.*;
class Foo {
public static void main(String args[]) {
if (args.length == 0) {
System.err.println(“Input Image file name…”);
System.exit(1);
}
JFrame oJFrame = new JFrame(“그림 보기 예제”);
ImageIcon oImageIcon = new ImageIcon(args[0]);
JLabel oJLabel = new JLabel(oImageIcon);
oJFrame.add(oJLabel);
oJFrame.pack();
oJFrame.setVisible(true);
oJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
실행방법
컴파일을 한 후, 도스창에서
java Foo photoshop_apples.jpg
이렇게 실행시킵니다. 그러면 GUI 창이 뜹니다.
만약 파일명에 공백이 있다면
java Foo “photoshop apples.jpg”
출처: http://mwultong.blogspot.com/2006/11/java-jpg-gif-png-image-file-viewer.html