夏晓静4/13代码修改

main
羊驼想睡觉 1 year ago
parent 2f6b3f5807
commit 7af39fd145

@ -147,10 +147,33 @@ public class CalculatorGUI extends JFrame {
String command = e.getActionCommand();
if (!command.equals("=")) {
if (command.equals("x²") || command.equals("x³") || command.equals("√x") || command.equals("x⁴")) {
// 计算函数值
// 获取表达式和操作符
String expression = displayField.getText();
String operator = "";
switch (command) {
case "x²":
operator = "²";
break;
case "x³":
operator = "³";
break;
case "√x":
operator = "√";
break;
case "x⁴":
operator = "⁴";
break;
}
// 计算函数值
double result = calculateFunction(expression, command);
// 构建历史记录字符串并添加到历史记录区
String historyEntry = expression + operator + " = " + result;
appendToHistory(historyEntry);
// 显示结果在实时显示区
displayField.setText(Double.toString(result));
} else if (command.equals("C")) {
// 清除实时显示区域的算术式
displayField.setText("");
} else {
displayField.setText(displayField.getText() + command);
}

Loading…
Cancel
Save