Java / Swing:如何正确使用FlowLayout在JFrame上添加多个JPanel?

时间:2015-01-22 22:43:00

标签: java swing nullpointerexception jpanel flowlayout

我想在JFrame中添加两个JPanel,我尝试了这个:

JPanel container;
JPanel jp;
JPanel jp2;
FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
container.setLayout(layout);
jp = new Drawing();
jp2= new Drawing2();
container.add(jp);
container.add(jp2);
setContentPane(container)
setVisible(true);

container.setLayout给了我

  

显示java.lang.NullPointerException

你能帮帮我吗?谢谢你。

0 个答案:

没有答案