Multiple JDialog windows causing unresponsiveness
I'm developing a program that has a main GUI window (JFrame) and multiple smaller JDialog windows.
I started noticing a great deal of unresponsiveness in my program, and I think it has something to do with the way I've been using threads. Only after writing my prog. and seeing the problems have I started reading about multi-threading and swing but some articles are confusing or contradicting... so essentially, my question is: what am I doing wrong.
Here's somewhat detailed description of my program:
1. The main GUI window displays a "live" animation of a landscape with moving objects within it.
2. The JDialog windows display looped playback of certain areas in the main GUI window.
3. The main GUI has various "small window managers", each manager holds references to a group of small windows and can pass them messages from the main GUI, and also make them visible/invisible so the user an page through more small windows than the screen can fit. Every manager implements the Runnable interface and I call Thread thread = new Thread(this).start( ) in the manager's constructor.
3. I have a server dedicated to sending new frames to the main GUI for the "live" image. The same server can also be queried for the smaller frames of the small windows - it has a built-in buffer where it stores old frames so that the small JDialog windows can get past frames of a certain region which are then sotred by the each small window and displayed in order.
4. One can also interact with each small JDialog window by clicking it with the mouse (I'm using the mouseClicked event) and then pressing a key to change that window's properties or even tell the main GUI window something about the region that the selected small window represents.
5. All together, everything is working. I put the main GUI window on the main( ) thread, where it loops through and updates its own frames to display the live picture - that same loop also interacts with the server to decide when to create new small windows.
6. Each small window works on its own thread. Each small window class implements the Runnable interface and I call Thread thread = new Thread(this).start( ) in the small window's constructor. (Should I use a worker thread instead? and if so, where should I invoke it later from? In the main GUI or within the small window's constructor?)
7. Each small window is its own ActionListener/MouseListener and knows to change properties or talk to its manager when the event needs to be passed on.