实验代码
package Circle; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; public class Gou { public static void main(String[] args) { JFrame frame = new JFrame("九宫格"); frame.setLayout(new FlowLayout(FlowLayout.CENTER,4,4)); JButton but=null; for (int i=1;i<=9;i++){ but =new JButton(i+""); frame.add(but); //加入按钮 } frame.pack(); frame.setVisible(true); } }
实验结果截图