|
|
@ -71,9 +71,9 @@ public class CalculatorController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String firstNumberText = (firstNumber % 1 == 0) ? String.valueOf((int) firstNumber) : String.valueOf(firstNumber);
|
|
|
|
String firstNumberText = (firstNumber % 1 == 0) ? String.valueOf((int) firstNumber) : String.valueOf(firstNumber);
|
|
|
|
operator = op;
|
|
|
|
operator = op;
|
|
|
|
currentInput.setLength(0); // 清空当前输入以便输入下一个数字
|
|
|
|
|
|
|
|
isOperationClicked = true;
|
|
|
|
isOperationClicked = true;
|
|
|
|
inputField.setText(firstNumberText + " " + operator); // 显示当前操作
|
|
|
|
currentInput.append(operator);
|
|
|
|
|
|
|
|
inputField.setText(firstNumberText + " " + operator + " "); // 显示当前操作
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
@ -140,7 +140,6 @@ public class CalculatorController {
|
|
|
|
if (currentInput.length() > 0) {
|
|
|
|
if (currentInput.length() > 0) {
|
|
|
|
// 移除最后一个字符
|
|
|
|
// 移除最后一个字符
|
|
|
|
currentInput.deleteCharAt(currentInput.length() - 1);
|
|
|
|
currentInput.deleteCharAt(currentInput.length() - 1);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果最后一个字符是空格且还有字符,继续删除空格(用于清理运算符后面的空格)
|
|
|
|
// 如果最后一个字符是空格且还有字符,继续删除空格(用于清理运算符后面的空格)
|
|
|
|
while (currentInput.length() > 0 && currentInput.charAt(currentInput.length() - 1) == ' ') {
|
|
|
|
while (currentInput.length() > 0 && currentInput.charAt(currentInput.length() - 1) == ' ') {
|
|
|
|
currentInput.deleteCharAt(currentInput.length() - 1);
|
|
|
|
currentInput.deleteCharAt(currentInput.length() - 1);
|
|
|
|