package com.sunzhiyan; import java.awt.*; import javax.swing.*; public class Demo_2 extends JFrame{ /** * @param args */ JButton jb[] = new JButton[10]; public static void main(String[] args) { // TODO Auto-generated method stub Demo_2 demo = new Demo_2(); } public Demo_2() { for(int i=0;i<9;i++){ jb[i] = new JButton("123"); this.add(jb[i]); } //前两个参数是设置网格的横纵,后面两个是设置之间的间距 this.setLayout(new GridLayout(3,3,50,50)); //设置一个窗体的基本方法 this.setTitle("jisuanqi"); this.setSize(400,400); this.setLocation(200,200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }