Java 如何从其他函数写入JTextArea?
我的应用程序就像网络游戏一样工作,我从服务器收到消息,我想在我的JTextArea中显示它们。代码如下所示:Java 如何从其他函数写入JTextArea?,java,swing,jtextarea,Java,Swing,Jtextarea,我的应用程序就像网络游戏一样工作,我从服务器收到消息,我想在我的JTextArea中显示它们。代码如下所示: public class klient extend JFrame{ ...declarations JTextArea areaText; public klient(){ setSize(600,300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("examp
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();
}
我是否能够以某种方式将行中的字符串添加到JTextArea区域文本中 应该是这样的
okno.getAreaText().append(line);
其中getAreaText()方法返回类的areaText字段。是,就是这样。我工作了一整天,一整夜,都想不出来:D谢谢