具体代码实现:
package JSQ;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.util.Stack;
import java.util.regex.Pattern;
public class Calculator extends JFrame implements ActionListener {
private String []KEYS={"7","8","9","AC","4","5","6","-","1","2","3","+"
,"0","XGQ","=","/","(",")",".","*"};
private JButton keys[]=new JButton[KEYS.length];
private JTextArea res=new JTextArea("0.0");
private JTextArea his=new JTextArea();
private JPanel jp1=new JPanel();
private JPanel jp2=new JPanel();
private JScrollPane gdt1=new JScrollPane(res);
private JScrollPane gdt2=new JScrollPane(his);
private JScrollPane gdt3=new JScrollPane(his);
private JLabel label=new JLabel("历史记录");
private String b="";
public Calculator() {
super("Calculator");
res.setBounds(20,18,255,115);
res.setAlignmentX(RIGHT_ALIGNMENT);
res.setEditable(false);
his.setBounds(290,40,250,370);
his.setAlignmentX(LEFT_ALIGNMENT);
his.setEditable(false);
label.setBounds(300,15,100,20);
jp2.setBounds(290,40,250,370);
jp2.setLayout(new GridLayout());
jp1.setBounds(20,18,255,155);
jp1.setLayout(new GridLayout());
res.setLineWrap(true);
res.setWrapStyleW