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);
}
}