import javax.swing.*; import java.awt.BorderLayout; import java.awt.GridLayout; public class Ckou { JFrame f; JPanel p; JTextField t; GridLayout g1; JButton a[]=new JButton[16]; public Ckou(){ f= new JFrame("计算器"); g1= new GridLayout(4,4); p= new JPanel(); p.setLayout(g1); t = new JTextField(); a[0]=new JButton("7");a[8]=new JButton("1"); a[1]=new JButton("8");a[9]=new JButton("2"); a[2]=new JButton("9");a[10]=new JButton("3"); a[3]=new JButton("/");a[11]=new JButton("-"); a[4]=new JButton("4");a[12]=new JButton("0"); a[5]=new JButton("5");a[13]=new JButton("."); a[6]=new JButton("6");a[14]=new JButton("="); a[7]=new JButton("*");a[15]=new JButton("+"); f.add(t,BorderLayout.NORTH); f.add(p,BorderLayout.CENTER); for(int i=0;i<16;i++){ p.add(a[i]); } f.setSize(400,300); f.setVisible(true); } public static void main(String[] args) { new Ckou(); } }