I'm trying to create a simple script that will allow a pop up of images and text. The window is poping up but its blank with nothing on it. Anyone know what I am doing wrong?
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.*;
public class Thermomter {
public static void main(String[] args) {
ImageIcon cold = new ImageIcon("cold_thermomtor.png");
JLabel label = new JLabel();
label.setIcon(cold);
label.setText("omg this is painfull");
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
frame.add(label);
}
}
Try to put
frame.add(label);
first, after:
JFrame frame = new JFrame();
Like this:
JFrame frame = new JFrame();
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);