java74-GUL面板
//jPanel面板
//面向?qū)ο笏枷?#xff0c;面板,窗口的基礎(chǔ)之上再加窗口
import java.awt.*;
import javax.swing.*;
public class test09 extends JFrame {
? ? JPanel mb1,mb2;
? ? JButton an1,an2,an3,an4,an5;
? ? public ?static void main(String[] args){
? ? ? ? test09 lx1=new test09();//主函數(shù)調(diào)用即可
? ? }
? ? //定義一個(gè)構(gòu)造器
? ? public ?test09(){
? ? ? ? mb1=new JPanel();//默認(rèn)為流布局
? ? ? ? mb2=new JPanel();
? ? ? ? an1=new JButton("可樂");
? ? ? ? an2=new JButton("雪碧");
? ? ? ? an3=new JButton("芬達(dá)");
? ? ? ? an4=new JButton("檸檬");
? ? ? ? an5=new JButton("汽水");
? ? ? ? //添加組件先把面板上的組件添加,再添加jframe上的組件
? ? ? ? mb1.add(an1);
? ? ? ? mb1.add(an2);
? ? ? ? mb2.add(an3);
? ? ? ? mb2.add(an4);
?
? ? ? ? this.add(mb1,BorderLayout.SOUTH);
? ? ? ? this.add(mb2,BorderLayout.NORTH);
? ? ? ? this.add(an5);//邊界布局唄添加再中間的的組件可以不寫參數(shù)
? ? ? ? //設(shè)置標(biāo)題
? ? ? ? this.setTitle("歌謠");
? ? ? ? //設(shè)置初始位置
? ? ? ? this.setLocation(100,100);
? ? ? ? //設(shè)置大小
? ? ? ? this.setSize(180,180);
? ? ? ? //釋放窗口關(guān)閉的資源,這個(gè)要寫對
? ? ? ? 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)建對象
? ? }
}
運(yùn)行結(jié)果
?
總結(jié)
以上是生活随笔為你收集整理的java74-GUL面板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第五章网络互联技术
- 下一篇: ad hoc java_Java并发编程