【发布时间】:2016-03-19 12:26:54
【问题描述】:
两者有什么区别:
public class Test {
public static void main(String[] args) {
JButton button= new JButton("1");
button.setVisible(true);
JPanel panel= new JPanel();
panel.add(button);
panel.setVisible(true);
JFrame frame = new JFrame();
frame.add(panel);
frame.setVisible(true);
frame.pack();
}
}
和
public class Test {
public static void main(String[] args) {
JButton button= new JButton("1");
button.setVisible(true);
JFrame frame = new JFrame();
frame.add(button);
frame.setVisible(true);
frame.pack();
}
}
我知道 JPanel 是 GUI 组件的容器,但我真的看不出使用它的实用性。当然我错了,但我是从 Swing 开始的,所以......为什么我应该使用 JPanel?真正的目的是什么?
【问题讨论】: