源程序:
import java.io.* ;
import java.awt.* ;
import javax.swing.* ;
public class Test{
public static void main(String[] args){
JFrame frame = new JFrame("测试") ;
frame.setLayout(new FlowLayout(FlowLayout.CENTER , 3 , 3)) ;
JButton button = null ;
for(int i = 0 ; i < 9 ; i++){
button = new JButton("按钮 " + i) ;
frame.add(button) ;
}
frame.setSize(300 , 150) ;
frame.setVisible(true) ;
}
}
运行结果: