java中流式布局管理器(Flowlayout)的演示

/**
 * 2018.8.8
 * 作者:小孟鱼
 * 功能:流式布局管理器(Flowlayout)的演示
 */
package com.gui;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Test_gui_3 extends JFrame {
            //定义组件
            JButton jb1,jb2,jb3,jb4,jb5,jb6;
    
    
        public static void main(String[] args) {
            //类的对象实例化
            Test_gui_3 test_gui_3=new Test_gui_3();    
            }
        //构造函数
        public Test_gui_3()
        {
            //创建组件
            jb1=new JButton("关羽");
            jb2=new JButton("刘备");
            jb3=new JButton("张飞");
            jb4=new JButton("黄忠");
            jb5=new JButton("吕布");
            jb6=new JButton("貂蝉");
            //添加各个组件
            this.add(jb1);
            this.add(jb2);
            this.add(jb3);
            this.add(jb4);
            this.add(jb5);
            this.add(jb6);
            //设置布局管理器
             this.setLayout(new FlowLayout(FlowLayout.LEFT));//控制按钮的位置

            //给窗口设置一个标题
            this.setTitle("怀仁饺子馆管理系统");
            //给窗口设置大小,按像素计算(密度单位)
            this.setSize(300, 300);
            //禁止用户改变窗体的大小
            //this.setResizable(false);
            //设置窗口初始位置
            this.setLocationRelativeTo(null);
            //jf.setLocation(300, 300);
            //设置当关闭窗口是,保证JVM也退出
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //显示
            this.setVisible(true);
            
        }
}
 

猜你喜欢

转载自blog.csdn.net/weixin_42133768/article/details/81502375