java学习(72):GUL流式布局管理器
生活随笔
收集整理的這篇文章主要介紹了
java学习(72):GUL流式布局管理器
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//面向?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ò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)錯誤,由于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)閉的資源,這個要寫對this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//顯示界面this.setVisible(true);//不可動this.setResizable(false);//1繼承jframe類//2在最上方定義組件//3在構(gòu)造方法中創(chuàng)建組件//4在構(gòu)造方法添加組件//5設(shè)置窗體屬性//6顯示窗體//7在主函數(shù)創(chuàng)建對象}
}
運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的java学习(72):GUL流式布局管理器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fread、fwrite、fopen函数
- 下一篇: 图像基本运算概述型