java71-GUL边界布局管理器
//面向?qū)ο笏枷?#xff0c;邊界管理布局器
import java.awt.*;
import javax.swing.*;
public class test06 extends JFrame {
? ? JButton an1,an2,an3,an4,an5;//把需要的組件定義在這里
? ? public ?static void main(String[] args){
? ? ? ? test06 lx1=new test06();//主函數(shù)調(diào)用即可
? ? }
? ? //定義一個(gè)構(gòu)造器
? ? public ?test06(){
? ? ? ? an1=new JButton("東方");
? ? ? ? an2=new JButton("西方");
? ? ? ? an3=new JButton("南方");
? ? ? ? an4=new JButton("北方");
? ? ? ? an5=new JButton("中方");
? ? ? ? this.add(an1,BorderLayout.EAST);
? ? ? ? //括號(hào)里的參數(shù)都是固定的不可變 前面是對(duì)象 后面是布局管理器
? ? ? ? this.add(an2,BorderLayout.WEST);
? ? ? ? this.add(an3,BorderLayout.SOUTH);
? ? ? ? this.add(an4,BorderLayout.NORTH);
? ? ? ? this.add(an5,BorderLayout.CENTER);
? ? ? ? this.setTitle("歌謠");
? ? ? ? //設(shè)置初始位置
? ? ? ? this.setLocation(100,100);
? ? ? ? //設(shè)置大小
? ? ? ? this.setSize(180,180);
? ? ? ? //釋放窗口關(guān)閉的資源,這個(gè)要寫(xiě)對(duì)
? ? ? ? this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
? ? ? ? //顯示界面
? ? ? ? this.setVisible(true);
? ? ? ? //1繼承jframe類
? ? ? ? //2在最上方定義組件
? ? ? ? //3在構(gòu)造方法中創(chuàng)建組件
? ? ? ? //4在構(gòu)造方法添加組件
? ? ? ? //5設(shè)置窗體屬性
? ? ? ? //6顯示窗體
? ? ? ? //7在主函數(shù)創(chuàng)建對(duì)象
? ? }
}
運(yùn)行結(jié)果
?
總結(jié)
以上是生活随笔為你收集整理的java71-GUL边界布局管理器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: QPainter::drawPixmap
- 下一篇: 中国工程院院士高文:从大数据科学到人工智