java学习(72):GUL流式布局管理器
生活随笔
收集整理的這篇文章主要介紹了
java学习(72):GUL流式布局管理器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//面向對象思想,流式管理布局器
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();//主函數調用即可}//定義一個構造器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));靠左//添加布局管理器,以免添加出現錯誤,由于java默認的邊界布局管理器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("歌謠");//設置初始位置this.setLocation(100,100);//設置大小this.setSize(180,180);//釋放窗口關閉的資源,這個要寫對this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//顯示界面this.setVisible(true);//不可動this.setResizable(false);//1繼承jframe類//2在最上方定義組件//3在構造方法中創建組件//4在構造方法添加組件//5設置窗體屬性//6顯示窗體//7在主函數創建對象}
}
運行結果
總結
以上是生活随笔為你收集整理的java学习(72):GUL流式布局管理器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fread、fwrite、fopen函数
- 下一篇: 图像基本运算概述型