JAVA 流式布局管理器

//流式布局管理器
import java.awt.*;
import javax.swing.*;
public class Jiemian2 extends JFrame{
    
    //定义组件
    JButton[]    an    =    {null,null,null,null,null,null,null,null};
    
    public static void main(String[] args){
        //运行本类的构造方法
        Jiemian2 jiemian    =    new Jiemian2();
    }
    
    public Jiemian2(){
        
        //创建按钮
        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("开心果");
            
        //添加布局管理器,以免添加出现错误
        //由于java默认的是边界布局管理器,所以这里要更改为流式布局管理器
        //第二个参数是对齐方式,LEFT,RIGHT默认居中对齐
        //this.setLayout(new FlowLayout());
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        
        //添加按钮
        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("流式布局Flowlayout");
        //设置窗口的宽高
        this.setSize(300,300);
        //设置窗口出现对于屏幕的位置
        this.setLocation(100,100);
        //禁止拉大拉小
        this.setResizable(false);
        //关闭窗口后释放资源
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //输出窗口
        this.setVisible(true);
    }
    
}