Reputation: 710
I want execute ExampleSwingWorker1 from Main GUI. Main GUI class compile and doing some jFrame and DB operations and show main app screen to user. And I have another class for store all of my Swingworkers.
public class WorkerClass {
public class ExampleSwingWorker1 extends SwingWorker<Void, Void> {
protected Void doInBackground() throws Exception {
process1();
process2();
process3();
process4();
process5();
process6();
return null;
}
public void done() {
Toolkit.getDefaultToolkit().beep();
}
}
}
Button Action in MainGui Class;
private void buttonRefreshActionPerformed(java.awt.event.ActionEvent evt) {
WorkerClass.ExampleSwingWorker1 trying = new WorkerClass.ExampleSwingWorker1();
}
I tried with the above methods for instantiating ExampleSwingWorker1 but it's not possible. But this Oracle Link offer this method for reach inner class.
Upvotes: 1
Views: 349
Reputation: 14413
You need an instance of WorkerClass
first
Workerclass worker = new WorkerClass();
WorkerClass.ExampleSwingWorker1 trying = worker.new ExampleSwingWorker1();
trying.execute();
Read more: Inner classes|Nested classes
Note: If it doesn't use WorkerClass instance method's think it to make it static
then you don't need an instance of WorkerClass to create a ExampleSwingWorker1
instance.
Note2: It's recommended that you add @Override
annotation. Reasons? Read here
Upvotes: 1