【问题标题】:Java Appending a character to a textareaJava 将字符附加到文本区域
【发布时间】:2011-02-14 20:35:03
【问题描述】:

我希望将一个字符附加到 textarea 中。我有一个简单的 GUI,其设计看起来像一部手机,我希望能够单击其中一个按钮并使用该字符更新 textarea。如果我单击另一个按钮,我希望能够将该字符附加到第一个按钮。我该怎么做呢?显然现在它只是在 textarea 中设置该按钮的字符,并在单击另一个按钮时被替换。

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");
    }

【问题讨论】:

    标签: java user-interface button jtextarea


    【解决方案1】:
    TextArea.append(newText);
    

    【讨论】:

    • @adam08 - 如果解决了问题,请务必将您的问题标记为已回答!
    猜你喜欢
    • 1970-01-01
    • 2013-05-21
    • 2013-08-19
    • 2015-11-25
    • 1970-01-01
    • 2013-12-22
    • 2016-06-08
    • 2014-09-03
    • 2014-01-03
    相关资源
    最近更新 更多