I write a calculator and want to get the Text of a JTextField and split it into two Variables (number1 and number2). That won´t work as i get everytime a 0.0 as a Result. How can I get that to work? Here you see the Minus Operation:
else if (action.equals("-")) {
String calc = TextField.getText();
String lookfornumber = calc.substring(calc.lastIndexOf("-") + 1);
double zahl2 = Double.parseDouble(lookfornumber);
String looknumberbefore = calc.substring(calc.lastIndexOf("-") + 2);
double zahl1 = Double.parseDouble(looknumberbefore);
erg = zahl1 - zahl2;
answer = String.format("%.1f - %.1f = %.2f", zahl1, zahl2, erg);
TextField.setText(answer);