Threading problem.

T

toton

Hi,
I have a custom control, (extended from JComponent) which also
implements MouseListener and MouseMotionListener & Runnable (or can
have a seperate Runnable implementation also).
Say the run method generates a set of random number (actually it do
something more) and store them in a GeneralPath member field named
path. It also stores it in another member field named GeneralPath
allPath .
Now what I want when mousePressed event occures it clears the the path
(but not allPath) and starts the thread. The thread in turn adds a
random point on the path. then yield , repaint ,sleep for 5 ms.
when the mosueReleaseed occures, it makes the thread null. Now the
thread to all a point to the path (and allPath) only when mouse is
pressed. thus I store mousePressed field in a volatile boolean and
check for it before adding.
allPath purely stores all of the random points , while path to store
random points between a mousePressed & mouseRealeased.
Now, I am experiencing some threading problem . what other
synchronization is needed ? I am doubtfull on mouse realease I make the
thread null, and immediately use mousepress what happens?
 
T

Thomas Hawtin

toton said:
Now, I am experiencing some threading problem . what other
synchronization is needed ? I am doubtfull on mouse realease I make the
thread null, and immediately use mousepress what happens?

I suggest avoiding threading as much as possible. javax.swing.Timer (not
java.util!) is your friend.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top