package com.zym.lesson6; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TestMixLayOut { public static void main(String[] args) { Frame frame=new Frame("课堂练习,混合布局"); //设置表格布局 2行 1列 frame.setLayout(new GridLayout(2,1)); //4个面板 // 上面第一个面板 设置左 中 右排列布局 Panel pane_up_all=new Panel(new BorderLayout()); //中间这个面板是上下两层,采用表格布局(2,1) Panel pane_up_middle=new Panel(new GridLayout(2,1)); // 下面第一个面板 设置左 中 右排列布局 Panel pane_down_all=new Panel(new BorderLayout()); //下中间这个面板是上下两层,采用表格布局 @2*2 (2,2) Panel pane_down_middle=new Panel(new GridLayout(2,1)); //组件按钮 Button button1=new Button("button TOP_left"); Button button2=new Button("button TOP_middle_up"); Button button3=new Button("button TOP_middle_down"); Button button1_1=new Button("button TOP_right"); Button button4=new Button("button DOW_left"); Button button5=new Button("button 1"); Button button6=new Button("button 2"); Button button7=new Button("button 3"); Button button8=new Button("button 4"); Button button9=new Button("button DOW_right"); //添加 上面的按钮 pane_up_all.add(button1,BorderLayout.EAST); pane_up_all.add(button1_1,BorderLayout.WEST); pane_up_middle.add(button2); pane_up_middle.add(button3); pane_up_all.add(pane_up_middle,BorderLayout.CENTER); //添加 下面的按钮 pane_down_all.add(button4,BorderLayout.EAST); pane_down_all.add(button9,BorderLayout.WEST); pane_down_middle.add(button5); pane_down_middle.add(button6); pane_down_middle.add(button7); pane_down_middle.add(button8); pane_down_all.add(pane_down_middle,BorderLayout.CENTER); //框架添加面板 frame.add(pane_up_all); frame.add(pane_down_all); frame.setSize(600,300); // frame.setBackground( Color.pink); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { //窗体关闭时做的事 @Override public void windowClosing(WindowEvent e) { // super.windowClosed(e); System.exit(0); } } ); } }
标签:lesson6,Button,down,middle,add,pane,讲解,new,课堂练习 From: https://www.cnblogs.com/zym97816/p/17736812.html