走迷宫的java源代码 走迷宫的java源代码怎么写( 六 )


} else if (s.equals("C")) {
// 如果是C删除当前计算
jt1.setText("0.");
op1 = op2 = 0;
str.replace(0, str.length(), " ");
preOp = currentOp = 0;
} else if (s.equals("MC")) {
// 如果是MC则清除缓冲区
String temp = "";
memory.replace(0, memory.length(), temp);
bM.setText(" ");
} else if (s.equals("MR")) {
// 如果按键为MR则恢复缓冲区走迷宫的java源代码的数到文本框
jt1.setText(memory.toString());
} else if (s.equals("MS")) {
// 如果按键为MS则将文本框走迷宫的java源代码的数存入缓冲区
String s1 = jt1.getText().trim();
memory.replace(0, memory.length(), s1);
bM.setText("M");
} else if (s.equals("M+")) {
// 如果按键为MS则将文本框值与缓冲区的数相加但不显示结果
String temp1 = jt1.getText().trim();
double dtemp = Double.parseDouble(temp1);
String temp2 = memory.toString();
dtemp += Double.parseDouble(temp2);
temp1 = String.valueOf(dtemp);
memory.replace(0, memory.length(), temp1);
} else if (s.equals("1/x")) {
// 如果按键为1/x则将文本框中的数据为它的倒数
String temp = jt1.getText().trim();
double dtemp = Double.parseDouble(temp);
jt1.setText("" + 1 / dtemp);
} else if (s.equals("sqrt")) {
// 如果按键为sqrt则将文本框中的内容求平方根
String temp = jt1.getText().trim();
double dtemp = Double.parseDouble(temp);
jt1.setText("" + Math.sqrt(dtemp));
} else if (s.equals("+")) {
str.setLength(0);
if (currentOp == 0) {
preOp = currentOp = 1;
op2 = 0;
jt1.setText("" + op1);
} else {
currentOp = preOp;
preOp = 1;
switch (currentOp) {
case 1:
op1 += op2;
jt1.setText("" + op1);
break;
case 2:
op1 -= op2;
jt1.setText("" + op1);
break;
case 3:
op1 *= op2;
jt1.setText("" + op1);
break;
case 4:
op1 /= op2;
jt1.setText("" + op1);
break;
}
}
} else if (s.equals("-")) {
str.setLength(0);
if (currentOp == 0) {
preOp = currentOp = 2;// op1=op2;op2=0;
jt1.setText("" + op1);
} else {
currentOp = preOp;
preOp = 2;
switch (currentOp) {
case 1:
op1 = op1 + op2;
jt1.setText("" + op1);
break;
case 2:
op1 = op1 - op2;
jt1.setText("" + op1);
break;
case 3:
op1 = op1 * op2;
jt1.setText("" + op1);
break;
case 4:
op1 = op1 / op2;
jt1.setText("" + op1);
break;
}
}
} else if (s.equals("*"))// *
{
str.setLength(0);
if (currentOp == 0) {
preOp = currentOp = 3;// op1=op2;op2=1;
jt1.setText("" + op1);// op1=op2;
} else {
currentOp = preOp;
preOp = 3;
switch (currentOp) {
case 1:
op1 = op1 + op2;
jt1.setText("" + op1);
break;
case 2:
op1 = op1 - op2;
jt1.setText("" + op1);
break;
case 3:
op1 = op1 * op2;
jt1.setText("" + op1);
break;
case 4:
op1 = op1 / op2;
jt1.setText("" + op1);
break;
}
}
} else if (s.equals("/"))// /
{
str.setLength(0);
if (currentOp == 0) {
preOp = currentOp = 4;// op2=1;
jt1.setText("" + op1);// op1=op2;
} else {
currentOp = preOp;
preOp = 4;
switch (currentOp) {
case 1:
op1 = op1 + op2;
jt1.setText("" + op1);
break;
case 2:
op1 = op1 - op2;
jt1.setText("" + op1);
break;
case 3:
op1 = op1 * op2;
jt1.setText("" + op1);
break;
case 4:
op1 = op1 / op2;
jt1.setText("" + op1);
break;
}
}
} else if (s.equals("="))// =

推荐阅读