首页 > Windows开发 > 详细

swing之flowlayout

时间:2016-11-04 16:32:49      阅读:195      评论:0      收藏:0      [点我收藏+]
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
//1.继承 JFrame类
//2.在最上方定义组件
//3.在构造方法中创建组件
//4、在构造方法中添加组件
//5.设置窗体属性
//6.显示窗体
//7.在主函数中创建对象

public class flowlayout1 extends JFrame{
   JButton [] a={null,null,null,null,null,null,null,null};
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        flowlayout1 f1=new flowlayout1();
    }

    public flowlayout1 ()
      {
        a[0]=new JButton("瓜子");
        a[1]=new JButton("话梅");
        a[2]=new JButton("西瓜");
        a[3]=new JButton("草莓");
        a[4]=new JButton("香蕉");
        a[5]=new JButton("苹果");
        a[6]=new JButton("栗子");
        a[7]=new JButton("黄瓜");
        //a[8]=new JButton("葡萄");
        
        this.setLayout(new FlowLayout(FlowLayout.LEADING));//默认是边界布局,如果想变成其他布局,加上
        
        this.add(a[0]);
        this.add(a[1]);
        this.add(a[2]);
        this.add(a[3]);
        this.add(a[4]);
        this.add(a[5]);
        this.add(a[6]);
        this.add(a[7]);
        
        this.setTitle("流式布局flowlayout");
        this.setSize(400,320);
        this.setLocation(100, 180);
        this.setResizable(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        
        
        
        
      }
}

技术分享技术分享

swing之flowlayout

原文:http://www.cnblogs.com/luo-mao/p/6030499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!