尝试创建GUI,但是每次我运行代码时,都不会发生/显示任何内容。我最小化了一切,以为它背后的一切,但我根本找不到。这是主要的课程:
import javax.swing.JFrame;
public class MainClass{
public static void main(String[] args) {
Gui frame = new Gui();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
这是我创建JFrame的类:
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.FlowLayout;
public class Gui extends JFrame{
private JLabel item1;
public Gui() {
super("Room Builder");
setLayout(new FlowLayout());
item1 = new JLabel("This is a nice sentence");
item1.setToolTipText("This is going to show up on hover");
add(item1);
}
}