I'm trying to receive streaming audio via UPD and when the program enters the for loop in the worker thread, it hangs and the event thread becomes unresponsive.
If I comment out the for loop, all is ok. Commenting out the audioPlayer line with the for loop uncommented makes no difference as long as the for loop is there. It seems like something with the loop itself.
Shouldn't I be able to run a long loop in the worker thread without disrupting the event thread?
Yikes, calling doInBackground directly is just like calling run on a standard thread: nothing gets done on a background thread in either case. For a SwingWorker you must call execute() (have you read the tutorial -- it's in there), and for a standard thread, you call start().
You can compare SwingWorker to Thread: calling doInBackground() is just like calling run() - no new thread, just all of the work in the calling thread. execute() and start() are the means for starting a new thread that will do the work.
wayne whitman wrote:Thanks Pete - I'm rethinking the approach. But I do see examples in the Swing tutorial using .start() to invoke the background thread.
That's the Thread tutorial. Have you read the SwingWorker tutorial. That's the one you need to look at now.
I'm really feeling like a greenhorn now. I reread some of the Swing tutorial to try and understand this better.
Made a little progress. Took the following example from the Sun Swing tutorial. Looked like a good approach.
When I tried using this approach in my code, I keep getting "is not abstract and does not override abstract method..." error at the worker = new SwingWorker() { line.
The funny thing is when I compile the example source on the command line, it compiles ok, but when I put it into a class as an example project in NetBeans, it gets the same error as when I try to incorporate it into my code.
Can anyone explain what is going on?
Why does the example compile on the command line ok, but gives the override abstract method error when you put the same code into NetBeans? (I only left out the Swing component code from the example)