布局管理器练习---实现窗口:

布局管理器练习------窗口实现_i++

思路:

1、frame

2、四个面板

​ border(左-button;中-面板;右边-button)

java代码实现:

import java.awt.*;

public class ExDemo {
	public static void main(String[] args) {
		//总 Frame
		Frame frame = new Frame();
		frame.setBounds(300, 400, 400, 400);
		frame.setBackground(Color.black);
		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));
		
		//上半部分OK
		p1.add(new Button("East-1"),BorderLayout.EAST);
		p1.add(new Button("West-1"),BorderLayout.WEST);
		p2.add(new Button("p2-btn-1"));
		p2.add(new Button("p2-btn-2"));
		p1.add(p2,BorderLayout.CENTER);
		
		//下半部分
		p3.add(new Button("East-2"),BorderLayout.EAST);
		p3.add(new Button("West-2"),BorderLayout.WEST);
		//中间4个
		for(int i=0 ; i<4 ; i++) {
			p4.add(new Button("for-"+i));
		}
		p3.add(p4,BorderLayout.CENTER);
		
		
		frame.add(p1);
		frame.add(p3);
		
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				super.windowClosing(e);
				System.exit(0);
			}
		});
	}
}