Hallo, ich sitze grad an einem Taschenrechner, der mich noch grau werden lässt
Das Problem ist nun, dass nach dem Klick auf eine Operationstaste, zum Bsp. "Plus" die Zahlen weiter im Feld bleiben und noch größer werden.
Wenn ich verusch "12+11 = 23" zu rechnen, kommt raus "12+1211 = 1223"
Wenn ich die Zeile
ersetze durch:
, kann ich keine mehrstellige Zahlen eintippen.
Hat jemand ein Tip für mich, wie ich das Problem angehen kann?
Java:
...
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
feld.setText(feld.getText() +"1");
}});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
feld.setText(feld.getText() +"2");
}});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
feld.setText(feld.getText() +"3");
}});...
Java:
...plus.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
textfeld[0] = feld.getText();
operator = PLUS;
intwert[0] = Double.parseDouble(feld.getText());
textfeld[0] = null;
}});...
Java:
...istGleich.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent gleich){
textfeld[1] = feld.getText();
intwert[1] = Double.parseDouble(textfeld[1]);
switch(operator){
case PLUS: double h = intwert[0] + intwert[1];
intwert[2] = h;
feld.setText(intwert[2] + "");break;
case MINUS: double b = intwert[0] - intwert[1];
intwert[2] = b;
feld.setText(intwert[2] + "");break;...
Das Problem ist nun, dass nach dem Klick auf eine Operationstaste, zum Bsp. "Plus" die Zahlen weiter im Feld bleiben und noch größer werden.
Wenn ich verusch "12+11 = 23" zu rechnen, kommt raus "12+1211 = 1223"
Wenn ich die Zeile
Java:
feld.setText(feld.getText() +"3");
ersetze durch:
Java:
feld.setText("3");
Hat jemand ein Tip für mich, wie ich das Problem angehen kann?