我在JTextArea中設置文本時遇到問題,我嘗試了setText(我更喜歡)並追加。我不知道問題出在哪裏,我得到了客戶端 - 服務器應用程序。我希望把他們的服務器中的JTextField發送消息,但是我無法在這裏是我的代碼:JTextArea setText無法正常工作
客戶端代碼是否正確reciving消息:
try
{
Socket socket = new Socket("localhost", PORT);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
DataOutputStream output = new DataOutputStream(socket.getOutputStream());
BufferedReader serverInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.writeBytes(outputString + "\n");
inputString = serverInput.readLine(); // private String inputString
mymodel.setTextArea(inputString); // this is not working
System.out.println(inputString); // this is working
socket.close();
}
catch...
setTextArea方法:
public void setTextArea(String string)
{
MyPanel mypanel = new MyPanel();
mypanel.textArea.setText(string); // debugger shows that the string contains message from server
}
由於setter方法不工作,我已經設置textarea爲public,實際上這個也不工作。我不知道問題出在哪裏,調試器也不幫助我。
尋找你的答案
編輯:
JTextTable代碼:
textArea = new JTextArea(1, 30);
textArea.setEditable(false);
panel.add(textArea, c);
我怎麼能訪問其他類的現有MyPanel的實例呢? – bbZ
如果你按照我的第一點來看教程,它會比黑客更容易(儘管絕對有可能) – MByD