java72-GUL流式布局管理器
//面向?qū)ο笏枷?#xff0c;流式管理布局器
import java.awt.*;
import javax.swing.*;
public class test07 extends JFrame {
? ? JButton[] an={null,null,null,null,null,null,null,null};//把需要的組件定義在這里
? ? public ?static void main(String[] args){
? ? ? ? test07 lx1=new test07();//主函數(shù)調(diào)用即可
? ? }
? ? //定義一個(gè)構(gòu)造器
? ? public ?test07(){
? ? ? ? an[0]=new JButton("蘋果");
? ? ? ? an[1]=new JButton("香蕉");
? ? ? ? an[2]=new JButton("李子");
? ? ? ? an[3]=new JButton("梨子");
? ? ? ? an[4]=new JButton("栗子");
? ? ? ? an[5]=new JButton("哈密瓜");
? ? ? ? an[6]=new JButton("西瓜");
? ? ? ? an[7]=new JButton("花生");
? ? ? ? this.setLayout(new FlowLayout());
? ? ? ?// this.setLayout(new FlowLayout(FlowLayout.LEFT));靠左
? ? ? ? //添加布局管理器,以免添加出現(xiàn)錯(cuò)誤,由于java默認(rèn)的邊界布局管理器
?
? ? ? ? this.add(an[0]);
? ? ? ? this.add(an[1]);
? ? ? ? this.add(an[2]);
? ? ? ? this.add(an[3]);
? ? ? ? this.add(an[4]);
? ? ? ? this.add(an[5]);
? ? ? ? this.add(an[6]);
? ? ? ? this.add(an[7]);
? ? ? ? this.setTitle("歌謠");
? ? ? ? //設(shè)置初始位置
? ? ? ? this.setLocation(100,100);
? ? ? ? //設(shè)置大小
? ? ? ? this.setSize(180,180);
? ? ? ? //釋放窗口關(guān)閉的資源,這個(gè)要寫對(duì)
? ? ? ? this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
? ? ? ? //顯示界面
? ? ? ? this.setVisible(true);
? ? ? ? //不可動(dòng)
? ? ? ? this.setResizable(false);
? ? ? ? //1繼承jframe類
? ? ? ? //2在最上方定義組件
? ? ? ? //3在構(gòu)造方法中創(chuàng)建組件
? ? ? ? //4在構(gòu)造方法添加組件
? ? ? ? //5設(shè)置窗體屬性
? ? ? ? //6顯示窗體
? ? ? ? //7在主函數(shù)創(chuàng)建對(duì)象
? ? }
}
運(yùn)行結(jié)果
?
總結(jié)
以上是生活随笔為你收集整理的java72-GUL流式布局管理器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python爬虫爬取智联招聘职位信息
- 下一篇: React 高阶组件HOC详解