Code:
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Container;
class ShowPicture {
public static void main(String args[]) {
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("j2fd.jpg");
JLabel label = new JLabel(icon);
Container contentPane = frame.getContentPane();
contentPane.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Habe ich aus dem Buch “Java für dummies“. Bei eclipse erscheint nur ein Kästchen ohne Bild.