Runnable Thread to update GUI components

Hi, I have a GUI with some fields and they get updated when I start a class that implements Runnable. I'm being forced to send the components in the class constructor in order for them to be used on the Runnable Thread side. For instance lets say I have a Jlabel that is a counter and that in my Runnable class I got the integer value ++, so I pass the JLabel to the Runnable class because otherwise the value won't change with time.

Is this the right way? because having swing components in the logic layer looks odd...

Pablo Mino
Greenhorn

Joined: Aug 11, 2009
Posts: 28

posted Jul 16, 2011 00:18:45

0

Ok I found a way to pass things between threads by using volatile.

I got 5 different messages that need to be passed to the GUI and not mentioning the volatile boolean that stops the thread. Is this the way?