Pergunta

    else if (cmd.equals("five"))
    {
        infixInput.setText("5");
    }
    else if (cmd.equals("six"))
    {
        infixInput.setText("6");
    }

So I have it set where when you press a calc button, the number is displayed on the infix textfield, but if I type 5, then 6 for example, the 6 will just replace the 5. How do I tell it to move over a space when a button is pressed

Foi útil?

Solução

You could try changing infixInput.setText("6"); to:

String text = infixInput.getText() + "6";
infixInput.setText(text);

This will append the "6" to the end of the text already displayed in the text field.

Outras dicas

Assuming your text field is not editable you can just append the text using code like the following:

infixInput.replaceSelection( "6" );

This code will insert the text into the Document (at the caret position, which will be add the end).

I find this approach is more accurate in case you ever use a DocumentListener on the text field since it will only fire an event for the text inserted, not the text removed and added.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top