Why is my Gui freezing?

Frozen Swing GUI

Posted 04 November 2009 - 09:16 AM

Hi,

I am writing a simple file server program with a swing gui. You get to enter a port and a directory to serve files from then hit the start button. It should send output such as errors, if any, your port #, directory, etc. to the displayArea textArea of the gui. However, once the staert button is hit, the gui locks up. I know the program is still running though because if I send all the output that I want to go to my gui to the console, that displays fine. The GUI just remains locked up though,

You shouldn't have infinite listener loops outside of threads, will cause all sorts of hell for your program.

Funny, that had just occurred to me right before I checked and saw your answer so I am glad to see my suspicions confirmed.

Can you help me out a bit with getting this into it's own thread? Can I simply create a class that is its own thread and instantiate it exactly at this point in the program or does this new thread need to communicate with others?

I'm really weak on threads so if you can give me a few hints to get started, I'd rally appreciate it.

Re: Frozen Swing GUI

I can point you in the right direction but I don't exactly have time to provide more specific example code right now.

You need to know how to use:

Streams
Observers/Observables
Runnable/Thread

You will need a listener class that extends Observable and implements runnable. You will need to make your GUI implement observer and write an update method inside your GUI to accept interactions through the stream that should be used to facilitate communication between the observer and the observable.

Re: Frozen Swing GUI

I can point you in the right direction but I don't exactly have time to provide more specific example code right now.

You need to know how to use:

Streams
Observers/Observables
Runnable/Thread

You will need a listener class that extends Observable and implements runnable. You will need to make your GUI implement observer and write an update method inside your GUI to accept interactions through the stream that should be used to facilitate communication between the observer and the observable.

Thanks, that ought to get me moving in the right direction. If anyone else is watching this thread, here is my latest attempt, which is somewhat of a move in the direction you were speaking of, but lacking much of it.

I nixed that whole try catch block with the while loop inside spawnConnection and instead instantiated a ConnectionSpawner object and passed it as parameters all of the variables and objects that were working inside it.

Here's the code - which of course doesn't work, but if you have time later or someone else is interested in helping me out, I'd appreciate if you could help me fix or nudge me further in the right direction. Meantime, I'm researching Observers and Observables, which I've not encountered before.