Hi I 've developed a chat client which is a swing based interface . There is a login .Once the user clicks on login after feeding the account info , the client communicates with the server and after the server sends and "OK" , the client login screen hides and a chat window( comprising of 2 text areas) opens up. Now there are 2 things which are happening . 1) Sometimes that window(which opens up after login) doesn't move nor can i type anything in the windows textarea but i can recieve messages from the other clients in that window 2) Second thing is when a different window overlaps the client chat window and is then minimised , the client chat window becomes totally disabled. It becomes brown in color , that means it doesn't even show the components ( textarea) added to it. Any clue of what is going on ?? Thanks a ton in advance
The problem is that you are blocking the event thread somewhere. All event handling and screen repaints are done in the event thread, so if it gets blocked for some reason your application is basically locked up like you've seen. Code that runs in the event thread includes code in event handler methods (like actionPerformed() in actionListener) or code in the run() method of Runnables invoked through SwingUtilities.invokeLater() or invokeAndWait(). Things that can cause blocks are obvious Thread related ones like sleep() and wait(), along with methods that block on IO, like file reads and writes and socket reads and writes. Making a remote call is using socket IO, so I'm betting that the event thread is getting blocked making a call to your server that is getting called from the 'login' button's action listener. A way to fix this would be for the button's action listener to only start a thread that would make the call to the server for you. Then that separate thread would get blocked while the call is made, but the event thread is free to handle other events and repaints as soon as it exits your actionPerformed() after starting the thread.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jan 12, 2001
If this might be the prob then let me also tell you that it does not get blocked always . Most of the times it works fine .
Actually i am starting a thread as soon as i am flushing some string and the thread( a class implements runnable) which i am starting also provokes the chat window and also inturn start 2 threads , one for reading input and one for writing output .
Also , my chat window does open . It also reads messages but i am not able to write . What to do ? [ November 01, 2003: Message edited by: raghav mathur ]
Joined: Jan 12, 2001
Ok Nathan Do you mean to say that i should start the Thread which also pops up the chat window, seperatly and not when i click on the login button ? Is that your point ? If yes then i can do one thing. I can use flags . I mean to say when the user has looged in and the chat thread is to be started , i won't start it as soon as somebody clicks on login , but i shall set a flag , a boolean value so that when the Thread event for the button is over and the authentication with the server is sucessfull , the falg shall be set to "true" and after checking the flag value i shall start the thread( which pops up the chat window) What say you ? Thanks a ton in advance