我的笔记 FlowLayout 流式布局管理器

来源:互联网 发布:dht网络 编辑:程序博客网 时间:2024/06/10 20:46
import java.awt.*;
import javax.swing.*;
public class liushi extends JFrame{
    JButton[] an={null,null,null,null,null,null,null,null};
    public static void main(String[] args)
    {
        liushi B=new liushi();
    }
    public liushi()
    {
        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("可乐");
        this.setLayout(new FlowLayout());//声明使用FlowLayout流式布局管理器 要不默认BorderLayout边界管理器
        this.add(an[0]);//往JFrame里添加按钮
        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.setLayout(new FlowLayout(FlowLayout.LEFT));//向左对齐
        //this.setLayout(new FlowLayout(FlowLayout.RIGHT));//向右对齐
        this.setSize(380,120);
        this.setLocation(200, 200);
        this.setResizable(false);  //设置窗口是否可以拉伸
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
}
0 0
原创粉丝点击