[英]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添加到我的JTextArea areaText嗎?
應該是這樣
okno.getAreaText().append(line);
其中getAreaText()方法返回類的areaText字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.