很快你就可以阅读我的代码并看到我把它作为图片的输出
/*
* Suppose I have 4 buttons vertically on the right hand side in First PAnel
* and 4 buttons on bottom horizantally in second Panel
* and 4 text fiedls in the center in 4 rows in third Panel
* Using Frame's default border
*/
JPanel p1= new JPanel();
for (int i = 0; i < right.length; i++) {
right[i]=new JButton("right "+(i+1));
p1.add(right[i]);
}
JPanel p2 = new JPanel();
for (int i = 0; i < down.length; i++) {
down[i] = new JButton("Down "+(i+1));
p2.add(down[i]);
}
JPanel p3=new JPanel();
for(int i = 0 ; i<text.length;i++){
text[i]=new JTextField(30);
p3.add(text[i]);
}
Container c =getContentPane();
c.add(p1,"East");
c.add(p2,"South");
c.add(p3,"Center");
setSize(300,400);
setVisible(true);
setDefaultCloseOperation(3);
输出 :
我想变成这样
注意第二个输出我使用了 Null 布局和 setBounds 方法
有什么建议吗?