I am trying to implement a Swing worker in my GUI. At the moment, I have a JFrame containing a button. When this is clicked, it should update the displayed tab, and then run the program in the background thread. Here is what I still have.
class ClassA { private static void addRunButton() { JButton runButton = new JButton("Run"); runButton.setEnabled(false); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ClassB().execute(); } }); mainWindow.add(runButton); } } class ClassB extends SwingWorker<Void, Integer> { protected Void doInBackground() { ClassC.runProgram(cfgFile); } protected void done() { try { tabs.setSelectedIndex(1); } catch (Exception ignore) { } } }
I do not understand how I can pass my cfgFile object. Can anyone advise on this?
source share