views:

140

answers:

1

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");
    }
+3  A: 
TextArea.append(newText);
Matthew Flaschen
Thanks Matthew. Appreciate it!
@adam08 - Make sure to mark your question as answered if it solved the problem!
webdestroya