I'm trying to get a GUI application to display an image. So far I've got this bit of code:
import javax.swing.*;
import java.awt.*;
public class DemoImage extends JFrame {
public void showImage() {
// creates the actual frame with title 'My GUI' and dimensions
JFrame frame = new JFrame("My GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 50);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
// Inserts the image icon
String imgStr = "image/pic1";
ImageIcon image = new ImageIcon(imgStr);
JLabel label1 = new JLabel(" ", image, JLabel.CENTER);
frame.getContentPane().add(label1);
frame.validate();
frame.setVisible(true);
}
public static void main(String[] args) {
DemoImage show1 = new DemoImage();
show1.showImage();
}
}
When i run it all i get is a window with a title "MY GUI". What else should i add so the image is actually displayed?
Thanks in advance