这两者有什么区别:
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?它的真正目的是什么?