I have a simple client-server program. In one thread GUI is running, when I click “connect” button on GUI, I connect to server in new thread, after some time I receive some data from server and I want to pass it to GUI – how can I do that?
Share
Pass a reference to your GUI object to the reading thread, and have the reading thread invoke a method of the GUI instance when he has received the data.
If the GUI is a Swing GUI, you’ll need to wrap the call into
SwingUtilities.invokeLater():and in the reading thread:
Note that SwingWorker is designed specifically for this kind of use-case.