如何从其他函数写入 JTextArea?

How to write into JTextArea from other functions?

我的应用程序作为网络游戏运行,我从服务器获取消息,我想在我的 JTextArea 中显示它们。代码如下所示:

public class klient extend JFrame{
    ...declarations
    JTextArea areaText;

public klient(){
    setSize(600,300);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("example");
    setLocationRelativeTo(null);
    getContentPane().add(createComponents());
}

public JPanel createComponents(){
    JPanel mainPanel = ...
    ....
    Jpanel games = ....

    areaText = new JTextArea(...);
    areaText.setFont...
    ....
    areaText.setEditable(false);

    games.add(new JScrollPane(areaText, JscrollPane.V..., JScrollPane.H...));
}
}

然后我有经典的主要功能

public static void main (String[] args){
    ....
    klient okno = new klient();
    ....
    line = reader.readLine();
}

我能否以某种方式将 String from line 添加到我的 JTextArea areaText 中?

应该是这样的

okno.getAreaText().append(line);

其中getAreaText()方法returnsclass的areaText字段。