No good, thanks for clarification on the right method to use though. I think my problem is how I coded threading into my program. I am new to threads and don't think I implemented it properly.
I have 2 classes, one GUI class, and one class that is instantiated on a thread to do the actual work, and multiple threads of this same class can be created and working at the same time. The cursor should only change back when all the threads are finished. The only way I could figure out how to prevent using static everywhere, and yet still call on the GUI class from any thread created by the GUI class (to call container.setCursor()), was to create a GUI class instance, and pass the same instance as a variable to the constructor of every created thread.
private void convertActionPerformed(java.awt.event.ActionEvent evt) {
fileNameSelect = leftTextField.getText();
destNameSelect = rightTextField.getText();
frf = new FileReaderFrame();
if (threadcount > 1) {
return;
} else {
PatternRunner pr = new PatternRunner(frf,createAddressTwoFlag,isheader, singlequotequalifier);
pr.start();
}
threadcount++;
frf.container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
This is the method that a thread is supposed to call when finished in the GUI class.
public synchronized void threadDone() {
threadcount--;
if(threadcount == 0)
frf.container.setCursor(Cursor.getDefaultCursor());
}
Problem is, frf is the reference I pass into the threads, and its also what I use to change the cursor. Changing the cursor with the frf reference instead of the Main() created instance, the cursor doesnt change to the busy cursor as when I just called it in the Main() created instance. A new GUI reference doesn't seem to work, as I can't change all of the GUI variables that netbeans creates to use the reference I created instead of the first instance thats created by Main()
How do I call on the container variable in the Main() instantiated GUI class from my thread classes and not make everything static, and also not having a reference that only some of the objects can use? I hope i worded my question correctly. I am still a newb about static and how to prevent it, especially in threading. It's also possible I am misunderstanding something else entirely. Please correct me if needed. Thanks.