流式管理器FlowLayout

来源:互联网 发布:嗟乎时运不齐命途多舛 编辑:程序博客网 时间:2024/06/06 02:07
/*流式管理器*/
package com.i;


import java.awt.*;
import javax.swing.*;


public class Calculator extends JFrame{
JButton[] an = {null,null,null,null,null,null,null,null};
public static void main(String[] args){
//JButton an1,an2,an3,an4,an5;
Calculator a = new Calculator();
}


public Calculator(){
/*JButton an1 = new JButton("东");
JButton an2 = new JButton("西");
JButton an3 = new JButton("南");
JButton an4 = new JButton("北");
JButton an5 = new JButton("中");*/
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());//由于java默认的是边界布局管理器,
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("流式布局FlowrLayout");
this.setSize(500,400);
this.setLocation(300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}


 }
/*总结
 * 继承JFrame类
 * 在最上方定义组件
 * 在构造方法中添加组件
 * 设置窗体属性
 * 显示窗体
 * 在主函数中创建对象
 * 所有布局管理管理器可以添加任意组建,例如滚动条. 
 * */

















0 0
原创粉丝点击