我有一个更新JTextArea
inrun()
方法的代码。
但是当run
方法执行时,append()
方法不会被执行。
它打印incomingMessage
变量的当前值,但不会附加到JTextArea
.
public void run()
{
while (true)
{
try
{
if(serverSocketMessage==null)
{
serverSocketMessage = new ServerSocket(Constants.INCOMING_MESSAGE_PORT);
}
System.out.println("Listening to incoming messages");
ObjectInputStream objectInputSender;
String incomingMessage = null;
serverMessage = serverSocketMessage.accept();
objectInputSender = new ObjectInputStream(serverMessage.getInputStream());
Object objectMessage = objectInputSender.readObject();
if (objectMessage instanceof String)
{
incomingMessage = objectMessage.toString();
System.out.println("\nMessage\n"+incomingMessage);
if(incomingMessage!= null)
{
chatingJTextArea.append(incomingMessage);
System.out.println("Not null");
}
chatingJTextArea.append("\n");
chatingJTextArea.append(incomingMessage);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}