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

    xiaoxiao2021-04-14  32

    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);     } }
    转载请注明原文地址: https://ju.6miu.com/read-669748.html

    最新回复(0)