package second;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Layout {
private Frame f;
private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;//声明10个button
//构造函数,实例化button 1 - 10
Layout(){
b1 = new Button("继续");
b2 = new Button("取消");
b3 = new Button("确定");
b4 = new Button("继续");
b5 = new Button("取消");
b6 = new Button("确定");
b7 = new Button("确定");
b8 = new Button("确定");
b9 = new Button("确定");
b10 = new Button("确定");
}
public static void main(String[] args){
Layout ly = new Layout();
ly.show();//显示
}
private void show(){
f = new Frame("Layout顺序布局");//框架
f.setSize(50,200);//设置大小
f.setLayout(new FlowLayout(FlowLayout.LEFT,30,20));//设置布局管理器为顺序布局,从左到右,行间与列间(RIGHT|LEFT|CENTER)
f.add(b1);//将按钮添加到框架中
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.add(b8);
f.add(b9);
f.add(b10);
f.addWindowListener(new WindowAdapter(){//监视关闭按钮,不然TMD根本关不掉
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
f.setVisible(true);//最后显示出来
}
}
效果图: