GUI freeze after click on button

后端 未结 1 1072
离开以前
离开以前 2020-12-04 03:30

I\'m trying to create a client/server application. The problem is the confirm button on client side works for the first time input but if I hit the same button for the anoth

1条回答
  •  执笔经年
    2020-12-04 03:47

    When you click on a button, the actionPerformed method of your ActionListener is triggered on the Event Dispatch Thread. This thread is the one-and-only thread responsible for the UI.

    The UI will remain frozen until you leave the actionPerformed method (as the thread is occupied). So if your ActionListener blocks (e.g. with your fromServer.readLine() call), the UI will remain frozen until that blocking call is ended.

    That is why the general guideline is to offload long tasks to a worker thread. The Swing concurrency tutorial contains more information.

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