如果我将代码从第一个示例更改为第二个示例,则不会显示任何内容(请参见屏幕截图:
主类:
public class Main extends JTabbedPane {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f = new JFrame("Math");
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int x = dim.getWidth() > 800 ? (int) (dim.getWidth() / 2 - 400) : 0;
int y = dim.getWidth() > 800 ? (int) (dim.getHeight() / 2 - 300) : 0;
f.setBounds(x, y, 800, 600);
f.setResizable(false);
f.setContentPane(new Main());
}
Main() {
super();
addTab("Pythagoras", new Pythagoras());
}
}
毕达哥拉斯(截图 1):
public class Pythagoras extends JPanel{
Pythagoras() {
super();
setLayout(new FlowLayout());
JTextField j = new JTextField("Hi :)");
add(j);
}
}
毕达哥拉斯(截图 2):
public class Pythagoras extends JPanel{
Pythagoras() {
super();
setLayout(new FlowLayout());
}
}
毕达哥拉斯(截图 3):
public class Pythagoras extends JPanel{
Pythagoras() {
super();
setLayout(new FlowLayout());
add( new JLabel("This works!"));
}
}