6.0 流式布局
????????????? ?流式布局講解:嗶哩嗶哩視頻
????????????? ? 流式布局代碼實(shí)戰(zhàn):嗶哩嗶哩視頻? ? ? ? ? ? ? ????
????????????????顧名思義,流式布局像流水一樣,一個(gè)緊挨著一個(gè)。
??????????????????它和我們得邊界布局寫法格式上差不多,只不過流式布局需要指定一下
????????????????? this.setLayout(new FlowLayout(FlowLayout.LEFT));
????????????????

附上代碼:
?import javax.swing.*;
import java.awt.*;
class 流式布局管理器 extends JFrame{
JButton[] jbutton={null,null,null,null,null,null,null,null};
public static void main(String[] args){
? ? ? ? ? ? 流式布局管理器 jframe = new 流式布局管理器();
}
public 流式布局管理器(){
? ? ? ? ? ? ? ??//空間設(shè)置
????????????????jbutton[0]=new JButton("按鍵1");
????????????????jbutton[1]=new JButton("按鍵2");
????????????????jbutton[2]=new JButton("按鍵3");
????????????????jbutton[3]=new JButton("按鍵4");
????????????????jbutton[4]=new JButton("按鍵5");
????????????????jbutton[5]=new JButton("按鍵6");????
????????????????jbutton[6]=new JButton("按鍵7");
????????????????jbutton[7]=new JButton("按鍵8");
//設(shè)置布局
this.setLayout(new FlowLayout(FlowLayout.LEFT));
//添加控件
this.add(jbutton[0]);
this.add(jbutton[1]);
this.add(jbutton[2]);
this.add(jbutton[3]);
this.add(jbutton[4]);
this.add(jbutton[5]);
this.add(jbutton[6]);
this.add(jbutton[7]);
//設(shè)置圖形化
this.setVisible(true);
this.setTitle("流式布局管理器");
this.setSize(280,160);
this.setLocation(400,300);
this.setResizable(false);? ? //關(guān)閉可界面放大縮小功能
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
代碼下載:
?https://url79.ctfile.com/d/34437279-53055431-ec5575?p=8866 (訪問密碼: 8866)