FlowLayout流式布局的简单使用
FlowLayout类的常用方法及常量如下:
通过setLayout方法去添加对象(如下面代码的21行)或者创建对象(创建新对象就是默认的第六种构造方法)即可.
此类方法比较简单,参考代码如下
import javax.swing.*;
import java.awt.*;
class Windows2 {
private JFrame jf;
public JButton jbutton1;
public Windows2(){
jf=new JFrame("FlowLayout实例");
FlowLayout flowLayout=new FlowLayout(FlowLayout.LEFT,20,20);
for(int i=1;i<=9;i++){
jbutton1=new JButton("按键"+i);
jf.add(jbutton1);
}
jf.setLayout(flowLayout);
jf.setSize(400,300);
jf.setLocation(200,100);
jf.setVisible(true);
jf.setSize(400,300);
jf.setVisible(true);
}
}
public class Demo{
public static void main(String[] args) {
new Windows1();
}
}