希望对你有帮助
import java.awt.*;
import javax.swing.*;
public class zzzz {
JFrame f;
JButton one,two,three,four,five,six,seven,eight,nine,zero,point,equal,plus,minus,divide,multiply;
Container c;
JTextField j;
public zzzz(){
f=new JFrame("Calculator GUI");
f.setSize(250, 220);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
c=f.getContentPane();
Dimension d=new Dimension(42,25);
Dimension d1=new Dimension(220,35);
Dimension d2=new Dimension(165,200);
Dimension d3=new Dimension(45,200);
Dimension d4=new Dimension(200,30);
FlowLayout fl=new FlowLayout(FlowLayout.CENTER);
one=new JButton("1");
two=new JButton("2");
three=new JButton("3");
four=new JButton("4");
five=new JButton("5");
six=new JButton("6");
seven=new JButton("7");
eight=new JButton("8");
nine=new JButton("9");
zero=new JButton("0");
point=new JButton(".");
equal=new JButton("=");
plus=new JButton("+");
minus=new JButton("-");
divide=new JButton("/");
multiply=new JButton("x");
j=new JTextField();
j.setEditable(false);
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.RIGHT));
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
p3.setLayout(new FlowLayout(FlowLayout.CENTER));
p1.setPreferredSize(d1);
p2.setPreferredSize(d2);
p3.setPreferredSize(d3);
p1.setBackground(Color.BLACK);
p2.setBackground(Color.BLACK);
p3.setBackground(Color.BLACK);
j.setPreferredSize(d4);
one.setPreferredSize(d);
two.setPreferredSize(d);
three.setPreferredSize(d);
four.setPreferredSize(d);
five.setPreferredSize(d);
six.setPreferredSize(d);
seven.setPreferredSize(d);
eight.setPreferredSize(d);
nine.setPreferredSize(d);
zero.setPreferredSize(d);
point.setPreferredSize(d);
equal.setPreferredSize(d);
plus.setPreferredSize(d);
minus.setPreferredSize(d);
divide.setPreferredSize(d);
multiply.setPreferredSize(d);
p1.add(j);
p2.add(seven);
p2.add(eight);
p2.add(nine);
p3.add(divide);
p2.add(four);
p2.add(five);
p2.add(six);
p3.add(multiply);
p2.add(one);
p2.add(two);
p2.add(three);
p3.add(minus);
p2.add(zero);
p2.add(point);
p2.add(equal);
p3.add(plus);
c.setLayout(fl);
c.setBackground(Color.BLACK);
c.add(p1);
c.add(p2);
c.add(p3);
f.setVisible(true);
}
public static void main(String[] args) {
new zzzz();
}
}