p*a 发帖数: 592 | 1 You need to supply a separate thread for your communication
between client and server. Put all your socket code in that
separate thread on client side. pass the textField as argument
to that separate thread so when you get sth from the server,
you can just use setText() to display it in the textField. | p*a 发帖数: 592 | 2
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this is becoz your client code is a dead loop, where you are block
on every read from socket. Since you put it inside actionPerformed()
your actionPerformed will never return until your client code has
exception. That's why your GUI stuff is stuck.
As I said, let your runClient() method run as a separate thread.
in your actionPerformed(), start the thread running runClient().
For Example:
class ClientThread extends |
|