Sabrina Cafey wrote:Thank you Rob for suggesting I read Concurrency in Swing. To clarify my understanding - If I were to create a Runnable thread as shown in the code example I provided in my previous post, I have a good chance of causing issues given how the Swing Thread model is constructed. The javax.swing.Timer class handles interaction with the event-dispatching thread (EDT), which removes the risk of issues. Hopefully this is correct so far?
Correct.
I've seen your code, and I see one clear mistake - you cannot reuse a SwingWorker. A SwingWorker has a few states, and once it's done it can never be executed again. You'll need to create a new SwingWorker each time.
Your repaint in the done() method is good though. Two of SwingWorker's methods, process and done, are called on the EDT and can therefore interact with the GUI without any problems.
I'm also not sure if the invokeAndWait is going to work. I believe init() is called on the EDT, and you cannot call invokeAndWait from the EDT. That will lead to an error.