user330572
user330572

Reputation: 183

Java Appending a character to a textarea

I'm looking to appends a character to a textarea in. I have a simple GUI designed to look like like a mobile phone and I want to be able to click on one of the buttons and update the textarea with that character. If I click another button, I want to be able to append that character to the first. How do I do this? Obviously right now it is just setting the character for that button in the textarea and will be replaced when another button is clicked.

public void actionPerformed(ActionEvent e) {
    String source = e.getActionCommand();
    if (source.equals("1")) {
        TextArea.setText("1");
    } else if (source.equals("2abc")) {
        TextArea.setText("a");
    } else if (source.equals("3def")) {
        TextArea.setText("e");
    } else if (source.equals("4ghi")) {
        TextArea.setText("i");
    } else if (source.equals("5jkl")) {
        TextArea.setText("k");
    } else if (source.equals("6mno")) {
        TextArea.setText("o");
    } else if (source.equals("7pqrs")) {
        TextArea.setText("s");
    } else if (source.equals("8tuv")) {
        TextArea.setText("t");
    } else if (source.equals("9wxyz")) {
        TextArea.setText("x");
    }

Upvotes: 0

Views: 1638

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 284977

TextArea.append(newText);

Upvotes: 3

Related Questions