Frame窗口练习及总结

Frame

  1. Frame是一个*窗口
  2. Panel无法单独显示,必须添加到某个容器中
  3. 布局管理器:
    - 流式
    - 东西南北中
    - 表格
  4. 大小,定位,背景颜色,可见性,监听,自动布局(pack)

Frame窗口练习及总结

代码

package com.gui.lesson01;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Work01 {
    public static void main(String[] args) {
        Frame frame = new Frame("Jchoi");
        frame.setLayout(new GridLayout(2,3));
        frame.setBounds(100,100,400,300);
        Panel p1 = new Panel(new GridLayout(2,1));
        Panel p2 = new Panel(new GridLayout(2,2));
        Button b1 = new Button("b1");
        Button b2 = new Button("b2");
        Button b3 = new Button("b3");
        Button b4 = new Button("b4");
        Button b5 = new Button("b5");
        Button b6 = new Button("b6");
        Button b7 = new Button("b7");
        Button b8 = new Button("b8");
        Button b9 = new Button("b9");
        Button b10 = new Button("b10");

        frame.add(b1);
        frame.add(p1);
        frame.add(b4);
        frame.add(b5);
        frame.add(p2);
        frame.add(b10);

        p1.add(b2);
        p1.add(b3);

        p2.add(b6);
        p2.add(b7);
        p2.add(b8);
        p2.add(b9);

        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        
    }
}
上一篇:WPF的UI虚拟化


下一篇:grafana与zabbix的结合