当我添加或减去或尝试总结任何操作时,它不起作用。这就是我所拥有的,我相信它与框中显示的代码有关
//////////
/////////
我做错了什么?父类将按钮作为数组。
public void actionPerformed(ActionEvent e) {
// Get the source of this action
JButton clickedButton = (JButton) e.getSource();
// Get the existing text from the calculator
// displayField.
String dispFieldText = parent.getDisplayValue();
dot = dispFieldText.contains(".");
if (!dispFieldText.equals(""))
enteredNumber = Double.parseDouble(dispFieldText);
if (clickedButton.getText().equals("+")) {
selectedAction = "+";
currentNumber = enteredNumber;
parent.setDisplayValue("");
} else if (clickedButton.getText().equals("-")) {
selectedAction = "-";
currentNumber = enteredNumber;
parent.setDisplayValue("");
} else if (clickedButton.getText().equals("*")) {
selectedAction = "*";
currentNumber = enteredNumber;
parent.setDisplayValue("");
} else if (clickedButton.getText().equals("/")) {
selectedAction = "/";
currentNumber = enteredNumber;
parent.setDisplayValue("");
////////////////////////////////////////////////////////////////////////////////
} else if ((clickedButton == parent.buttons[11]) && (selectedAction != null)) {
if (selectedAction.equals("+")) {
currentNumber += enteredNumber;
parent.setDisplayValue("" + currentNumber);
////////////////////////////////////////////////////////////////////////////////
} else if (selectedAction.equals("-")) {
currentNumber -= enteredNumber;
parent.setDisplayValue("" + currentNumber);
} else if (selectedAction.equals("*")) {
currentNumber *= enteredNumber;
parent.setDisplayValue("" + currentNumber);
} else if (selectedAction.equals("/")) {
currentNumber /= enteredNumber;
parent.setDisplayValue("" + currentNumber);
}
}
else {
if (!clickedButton.getText().equals("=")) {
if ((clickedButton.getText().equals(".")) && dot) {
}
else {
// Get the button label
String clickedButtonLabel = clickedButton.getText();
parent.setDisplayValue(dispFieldText + clickedButtonLabel);
}
}
}
}
}