Skip to content
Snippets Groups Projects
Commit 4da10744 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Some little replacement work

parent 8ae35a93
No related branches found
No related tags found
No related merge requests found
......@@ -68,11 +68,29 @@ public class TaschenrechnerGui extends JFrame {
panel.add(button);
}
public String replaceSigns(String strDisplay) {
if(strDisplay.startsWith("= ") && !(strDisplay.endsWith("+") || strDisplay.endsWith("-") || strDisplay.endsWith("*") || strDisplay.endsWith("/"))) {
strDisplay = strDisplay.substring(strDisplay.length()-1);
} else {
strDisplay = strDisplay.replace("= ", "");
strDisplay = strDisplay.replace("**", "*");
strDisplay = strDisplay.replace("//", "/");
strDisplay = strDisplay.replace("/*", "*");
strDisplay = strDisplay.replace("++", "+");
strDisplay = strDisplay.replace("--", "-");
strDisplay = strDisplay.replace("-+-", "-");
strDisplay = strDisplay.replace("+-+", "+");
}
return strDisplay;
}
private class InsertAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent actionEvent) {
txtCalculation.setText(txtCalculation.getText() + ((JButton) actionEvent.getSource()).getText());
txtCalculation.setText(replaceSigns(txtCalculation.getText() + ((JButton) actionEvent.getSource()).getText()));
}
}
......@@ -80,7 +98,7 @@ public class TaschenrechnerGui extends JFrame {
@Override
public void actionPerformed(ActionEvent actionEvent) {
txtCalculation.setText(" = " + String.valueOf(berechnen(txtCalculation.getText())));
txtCalculation.setText("= " + String.valueOf(berechnen(txtCalculation.getText())));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment