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);
    }
    
}

 

转载于:https://www.cnblogs.com/phpyangbo/p/5158974.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值