【编写一个模拟计算器的程序.要包括以下方法:加法,减法,乘法,除法.每个方法至少有两个参数.】
编写一个模拟计算器的程序.要包括以下方法:加法,减法,乘法,除法.每个方法至少有两个参数.
【编写一个模拟计算器的程序.要包括以下方法:加法,减法,乘法,除法.每个方法至少有两个参数.】
编写一个模拟计算器的程序.要包括以下方法:加法,减法,乘法,除法.每个方法至少有两个参数.
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
publicclass计算器extendsJFrameimplementsActionListener{
privatefinalString[]KEYS={"7","8","9","÷","sqrt","4","5","6",
"×","%","1","2","3","-","1/x","0","+/-",".","+","="};
privatefinalString[]COMMAND={"Backspace","CE","C"};
privatefinalString[]M={"","MC","MR","MS","M+"};
privateJButtonkeys[]=newJButton[KEYS.length];
privateJButtoncommands[]=newJButton[COMMAND.length];
privateJButtonm[]=newJButton[M.length];
privateJTextFieldresultText=newJTextField();
privatebooleanfirstDigit=true;
privatedoubleresultNum=0.0;
privateStringoperator="=";
staticdoublemr;//记忆的数字
privatebooleanoperateValidFlag=true;
JPanelpanel[]=newJPanel[4];
public计算器(){
super("计算器");
init();
setBackground(Color.LIGHT_GRAY);
setResizable(false);
setLocation(588,250);
setSize(378,214);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);//窗口不能直接关闭
setVisible(true);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
if(JOptionPane.showConfirmDialog(null,"确定退出?","提示",2)==0){
System.exit(0);
}}});
}
privatevoidinit(){
setLayout(null);
for(inti=0;i