布局的小demo
package com.zishi.lesson01;
import java.awt.*;
//练习demo
public class TestLayout {
public static void main(String[] args) {
Frame frame = new Frame();
frame.setSize(400,300);
frame.setLocation(400,400);
frame.setBackground(new Color(255, 237, 53));
frame.setVisible(true);
frame.setLayout(new GridLayout(2,1));
//4个面板
Panel p1 = new Panel(new BorderLayout());
Panel p2 = new Panel(new GridLayout(2,1));
Panel p3 = new Panel(new BorderLayout());
Panel p4 = new Panel(new GridLayout(2,2));
//上面板的操作
p1.add(new Button("East-1"),BorderLayout.EAST);
p1.add(new Button("West-1"),BorderLayout.WEST);
p2.add(new Button("Top-1"));
p2.add(new Button("Top-2"));
p1.add(p2,BorderLayout.CENTER);
//下面板的操作
p3.add(new Button("East-2"),BorderLayout.EAST);
p3.add(new Button("West-2"),BorderLayout.WEST);
//中间4个
// p4.add(new Button("Under-1"));
// p4.add(new Button("Under-2"));
// p4.add(new Button("Under-3"));
// p4.add(new Button("Under-4"));
for (int i = 1; i < 5; i++) {
p4.add(new Button("Under-"+i));
}
p3.add(p4,BorderLayout.CENTER);
//将panel面板放到frame中
frame.add(p1);
frame.add(p3);
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/d98d8e0eded44ee0add5d05c2009d370.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1MTY4Nzg5,size_16,color_FFFFFF,t_70#pic_center)