• Post Reply Bookmark Topic Watch Topic
  • New Topic

readUTF locking up GUI

 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello (world),

The following code works when used outside of netbeans for when receiving input from the server:
while (true) {
jTextArea1.append("\n"+in .readUTF());
}

However, whenever used in netbeans, the entire GUI freezes until I kill the server. Furthermore, it's actually "working" in so far as when the server is finally shut off, the GUI is finally updated to reflect all of the messages that have come in.

What am I doing wrong? I moved to netbeans in order to make a nice gui -but now the application has stopped working Any help would be appreciated for this javaranch newbie. By the way, the server is sending out a writeUTF().

Not sure if this is the right category for this or not.

Thanks in advance!
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

In other words, don't call methods that can take a long time or block in the Event Dispatcher Thread.
 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir! Very interesting article- I'm blocking the Event Dispatcher Thread then. I'm trying to figure out how to use the invokeLater() method but am still trying to figure it out. Thanks again and will post again if I have additional questions.
 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have now:


Where appendMessage() is:


Only problem is, it doesn't work. Actually, obviously as a result of my lack of complete understanding and therefore incorrect implementation, it makes the gui lock up even more.

Any ideas?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the part that blocks the EDT


try it like this - the rest of the code should be OK

 
Roger Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great! What I ended up doing a little earlier was:



and:



Which works! I think that's basically what you had Michael but yours is much more succinct. Thanks so much for the help, I really appreciate it!
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Potentially this can already block your GUI:
If the host is unavailable, or the connection between the two machines is slow, this call can take longer than you expect.
Remember, any I/O, networking or database access is potentially blocking / slow, and shouldn't be handled in the EDT.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!