문제

    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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top