import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Calculator extends JFrame implements ActionListener{
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JTextField tfMemory=new JTextField();
JTextField tfResult=new JTextField();
//定义数字按键
JButton button_0=new JButton();
JButton button_1=new JButton();
JButton button_2=new JButton();
JButton button_3=new JButton();
JButton button_4=new JButton();
JButton button_5=new JButton();
JButton button_6=new JButton();
JButton button_7=new JButton();
JButton button_8=new JButton();
JButton button_9=new JButton();
//定义四则运算按键
JButton button_add=new JButton();
JButton button_sub=new JButton();
JButton button_mul=new JButton();
JButton button_div=new JButton();
JButton button_dot=new JButton();
JButton button_equal=new JButton();
//定义三角函数按键
JButton button_sin=new JButton();
JButton button_cos=new JButton();
JButton button_tan=new JButton();
//定义其他运算按键
JButton button_sqrt=new JButton();
JButton button_daoshu=new JButton();
JButton button_pow=new JButton();
//定义域存储器相关的按键
JButton button_MC=new JButton();
JButton button_MR=new JButton();
JButton button_MS=new JButton();
JButton button_MPlus=new JButton();
JButton button_MMinus=new JButton();
//定义两个常数按键
JButton button_PI=new JButton();
JButton button_E=new JButton();
//定义符号键和清零键
JButton button_sign=new JButton();
JButton button_CE=new JButton();
//定义布局方式
GridLayout grid1=new GridLayout();
GridBagLayout gridbag1=new GridBagLayout();
GridBagLayout gridbag2=new GridBagLayout();
//保存最近一次运算符
String recentOperation=null;
//保存最近一次的运算数据
String recentNum=null;
//描述当前输入状态,是重新输入还是接在后面,重新输入时为true
boolean isNew=true;
public Calculator(){
//为按键
注册监听器
button_0.addActionListener(this);
button_1.addActionListener(this);
button_2.addActionListener(this);
button_3.addActionListener(this);
button_4.addActionListener(this);
button_5.addActionListener(this);
button_6.addActionListener(this);
button_7.addActionListener(this);
button_8.addActionListener(this);
button_9.addActionListener(this);
button_add.addActionListener(this);
button_sub.addActionListener(this);
button_mul.addActionListener(this);
button_div.addActionListener(this);
button_dot.addActionListener(this);
button_equal.addActionListener(this);
button_sin.addActionListener(this);
button_cos.addActionListener(this);
button_tan.addActionListener(this);
button_sqrt.addActionListener(this);
button_daoshu.addActionListener(this);
button_pow.addActionListener(this);
button_MC.addActionListener(this);
button_MR.addActionListener(this);
button_MS.addActionListener(this);
button_MPlus.addActionListener(this);
button_MMinus.addActionListener(this);
button_PI.addActionListener(this);
button_E.addActionListener(this);
button_sign.addActionListener(this);
button_CE.addActionListener(this);
//设置按键特征(字体、颜色、内容)
but