import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
public class TestLayout {
public static void main(String[] args) {
Frame f = new Frame();
f.setLayout(new GridLayout(2, 1));
Panel p1 = new Panel(new BorderLayout());
Panel p2 = new Panel(new BorderLayout());
Panel p11 = new Panel(new GridLayout(2, 1));
Panel p21 = new Panel(new GridLayout(2, 2));
Button p1B1 = new Button();
Button p1B2 = new Button();
Button p1B3 = new Button();
Button p1B4 = new Button();
Button p2B1 = new Button();
Button p2B2 = new Button();
p11.add(p1B1);
p11.add(p1B2);
p1.add(p1B4, BorderLayout.WEST);
p1.add(p1B3, BorderLayout.EAST);
p1.add(p11, BorderLayout.CENTER);
p2.add(p2B1, BorderLayout.WEST);
p2.add(p2B2, BorderLayout.EAST);
for (int i = 0; i < 4; i++) {
p21.add(new Button());
}
p2.add(p21);
f.add(p1);
f.add(p2);
f.pack();
f.setVisible(true);
}
}
java awt 简单示例 Layout组合
最新推荐文章于 2023-04-23 16:41:00 发布