package javax.swing;
import java.awt.Container;
import java.awt.FlowLayout;
/*
* 流式布局
*/
public class LB extends JFrame {
public LB(){
setBounds(100,200,300,200); //设置窗口大小
setDefaultCloseOperation(EXIT_ON_CLOSE); //设置关闭规则,运行结束就关闭
Container c=getContentPane(); //获取窗口容器
c.setLayout(new FlowLayout()); //采用流式布局
for(int i=0;i<=9;i++) { //采用for循环,产生是个按钮
c.add(new JButton("按钮"+i));
}
setVisible(true); //设置窗口可见
}
public static void main(String[] args) {
new LB();
}
}
运行截图