Java - How to Create a MultiThreaded Game using SwingWorker
If I understood your code correctly, you are making a game where the human player has to click as fast as possible on all of his shapes while the PC is randomly clicking on shapes as well. The first one to clear all of his shapes win.
If that is correct, you probably want to adjust your SwingWorker
to
- loop until the game is finished. Currently your loop exit the first time the end of the loop is reached due to the
return
statement - Since you are not doing anything with the boolean return value of the
SwingWorker
, you might as well let it return void - No need to call
get
in thedone
method. The moment that method is called, theSwingWorker
has finished. You only seem interested in the intermediate results - In the
process
method, you might want to loop over all values. Note that theprocess
method is not called each time youpublish
something. The values you publish are grouped and passed in bulk to theprocess
method when the EDT (Event Dispatch Thread) is available