如何在java中向TextArea添加文本

时间:2017-10-12 18:31:33

标签: javascript java jquery intellij-idea

我有这段代码:



package com.butoane;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class App {
    private JButton apasaAiciButton;
    private JPanel Dunno;
    private JButton apoiaici;
    private JTextArea text1;

    public App() {
       String a = "H";
       String b = "e";
        apasaAiciButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                apoiaici.setEnabled(true);
                apasaAiciButton.setEnabled(false);
                text1.setText(toString(a));
            }

        });
        apoiaici.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                apoiaici.setEnabled(false);
                apasaAiciButton.setEnabled(true);
                apasaAiciButton.setText("Apasa iar aici");
                text1.setText(toString(b));
            }
        });
    }
    public static void main(String[] args) {
        JFrame frame = new JFrame("App");
        frame.setContentPane(new App().Dunno);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}




我想要做的是,当按下一个按钮时,文本字段得到H或E,如:Button1(apasaAici)被按下,文本得到H 按下Button2(apoiAici),文本区域在" H"之后得到一个E,并且,一遍又一遍地执行此操作,textarea每次获得HeHeHeHe,你得到它吗? / p>

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

JTextArea.append(String)

对于“H”按钮:

text1.append(a);

对于“e”按钮:

text1.append(b);