• Post Reply Bookmark Topic Watch Topic
  • New Topic

Odd JFrame Behavior  RSS feed

 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making a chat room and whenever I press the continue button, the new frame becomes transparent, one doesn't dispose, and I have to quit it with task manager.
Here is my code:


Any help apprieciated! Thanks!
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A ServerSocket blocks the current Thread waiting for data. Since you create the ServerSocket from the ActionListener the code is executing on the Event Dispatch Thread, which is the Thread the GUI uses for painting itself and handling events so you effectively block are GUI events.

The solution is to start your ServerSocket in a separate Thread.

Read the section from the Swing tutorial on Concurrency for more information.
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much!
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
_
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a client/server expert. Basically your code is still blocking on the accept() method. So you need a client to connect to the server and send some text before anything will happen.

Also, you have a problem with your port number because you create two instances of your Server class. The port number of the socket is always 0 because the port variable is initialized to 0 when your create a new instance of it.

You should not be using static variables. The code for the initial GUI must be completely self contained in the main() method. Then when you create the Server class you should pass in the value of your port field as a parameter.

Maybe the Java tutorial on Sockets will help.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Heg,
Please do not edit your posts once you get an answer. The way the discussion stands now, I cannot figure what was it you said to which Rob Camick suggested you refer to the Sockets tutorial.
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:@Heg,
Please do not edit your posts once you get an answer. The way the discussion stands now, I cannot figure what was it you said to which Rob Camick suggested you refer to the Sockets tutorial.


Sure Maneesh! Thanks for the advice!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!