一、Panel是AWT中的另一個典型的容器,它代表不能獨立存在、必須放在其他容器中使用。
1、可作為容器來盛裝其他組件,為放置組件提供空間。
2、不能單獨存在,必須放置到其他容器當中。
3、默認使用FlowLayout作為布局管理器。
1 public class PanelTest extends Frame
2 {
3 public static void main(String[] args)
4 {
5 Frame f = new Frame();
6 Panel p = new Panel();
7 p.add(new TextField(20));
8 p.add(new Button("百度"));
9 f.add(p);
10 f.setBounds(50, 50, 300, 300);
11 f.setVisible(true);
12 }
13 }

二、FlowLayout布局管理器
在FlowLayout布局管理器中,組件像流水一樣向某方向流動(排列),遇到障礙(邊界)就折回,重頭開始排列。
三個構造器:
FlowLayout:使用默認的對齊方式及默認的垂直間距、水平間距創建FlowLayout布局管理器。
FlowLayout(int align):使用指定的對齊方式及默認的垂直間距、水平間距創建FlowLayout布局管理器。
FlowLayout(int align,int hgap,int vgap):使用指定的對齊方式及指定的垂直間距、水平間距創建FlowLayout布局管理器。
1 public class FlowLayoutTest
2 {
3 public static void main(String[] args)
4 {
5 Frame f = new Frame();
6 f.setLayout(new FlowLayout(FlowLayout.LEFT,20,5));
7 Button b1 = new Button("a1");
8 Button b2 = new Button("a2");
9 Button b3 = new Button("a3");
10 f.add(b1);
11 f.add(b2);
12 f.add(b3);
13 f.pack();
14 f.setVisible(true);
15
16 }
17 }

三、BorderLayout布局管理器
BorderLayout將容器分為EAST(東),SOUTH(南),WEST(西),NORTH(北),CENTER(中)五個區域,普通組件可以放在這5個區域中的任意一個。
構造器:
BorderLayout():使用默認的水平間距、垂直間距創建BorderLayout布局管理器
BorderLayout(int hgap,int vgap):使用指定的水平間距、垂直間距創建BorderLayout布局管理器。
1 public class BorderLayoutTest extends Frame
2 {
3 public static void main(String[] args)
4 {
5 Frame f = new Frame();
6 f.setLayout(new BorderLayout(30, 5));
7 f.add(new Button("南"),BorderLayout.SOUTH);
8 f.add(new Button("北"),BorderLayout.NORTH);
9 f.add(new Button("中"));
10 f.add(new Button("東"),BorderLayout.EAST);
11 f.add(new Button("西"),BorderLayout.WEST);
12
13 f.pack();
14 f.setVisible(true);
15 }
16 }

四、GridLayout布局管理器