importjava
BorderLayout;importjava
Color;importjava
GridLayout;importjava
ActionEvent;importjava
ActionListener;importjavax
JButton;importjavax
JFrame;importjavax
JPanel;importjavax
JTextField;/***一个计算器,与Windows附件自带计算器的标准版功能、界面相仿
但还不支持键盘操作
*/publicclassCalculatorextendsJFrameimplementsActionListener{/**计算器上的键的显示名字*/privatefinalString[]KEYS={"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-","
","+","="};/**计算器上的功能键的显示名字*/privatefinalString[]COMMAND={"Backspace","CE","C"};/**计算器左边的M的显示名字*/privatefinalString[]M={"","MC","MR","MS","M+"};/**计算器上键的按钮*/privateJButtonkeys[]=newJButton[KEYS
length];/**计算器上的功能键的按钮*/privateJButtoncommands[]=newJButton[COMMAND
length];/**计算器左边的M的按钮*/privateJButtonm[]=newJButton[M
length];