When hitting a JButton to connect to a server , the program freezes

后端 未结 1 485
醉酒成梦
醉酒成梦 2021-01-27 10:28

I am making a simple 1v1 \"private chat\" using TCP in java. Currently, i have a problem whenever i am using JButtons. This is my first attempt at using JButtons and ActionListe

1条回答
  •  礼貌的吻别
    2021-01-27 11:14

    Your server code runs well, but your client is blocking the Event Dispatching Thread when you call connectToServer.

    The Event Dispatching Thread is responsible for, amongst other things, processing repaint requests and new input events. If you block this thread for any reasons, then there is no way that the Event Dispatching Thread can process any new events...

    All blocking or long running tasks should be executed out side of the context of the Event Dispatching Thread.

    Take a look at Concurrency in Swing for more details

    0 讨论(0)
提交回复
热议问题