布局的小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); } }