Wenslauw wrote:
I have a thread that reads from a socket and I want to put the data
that's read into a JTextArea in my gui. What would be the prettiest
way of doing this? Listeners? Passing the JTextArea to the thread?
Thanks in advance for any answers.
I created a class, StringSocketThread that takes a Socket on creation
and then wraps itself inside a Thread (it implements Runnable) and
starts listening to the socket. I think of it as a Socket Agent. When a
line is received, or the socket state changed, all listeners are
informed. I defined the listener interface internally, so listening
classes must implement StringSocketThread.Listener.
I don't believe there are any problems with this approach, but I'm not
one hundred percent certain, which is why I post this message here.
Please inform me if I'm missing something. I think I have a basic
understanding of thread safety, but you never know..
Geeetz,
Pieter Bonne.