I have main file that use ProgressBar. In main file I call ProgressBar as
ProgressBar pbFrame = new ProgressBar();
pbFrame.setVisible(true);
I call ProgressBar after calling executable file "calculate.exe" to show that calculate.exe is working now. But ProgressBar opens when "calculate.exe" finished. How to make parallel executing of "calculate.exe" and ProgressBar? I hear about SwingWorker but I absolutely don't understand how to use it in my application.
My ProgressBar file:
public class ProgressBar extends JFrame {
static private int BOR = 10;
private String filename;
public ProgressBar() {
super("Calculating progress");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(BOR, BOR, BOR, BOR));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new JLabel("Calculating..."));
panel.add(Box.createVerticalGlue());
JProgressBar progressBar1 = new JProgressBar();
progressBar1.setIndeterminate(true);
panel.add(progressBar1);
panel.add(Box.createVerticalGlue());
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS));
buttonsPanel.add(Box.createVerticalGlue());
JButton quitButton = new JButton("OK!");
quitButton.setHorizontalAlignment(JButton.CENTER);
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
dispose();
}
});
panel.add(quitButton);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
setPreferredSize(new Dimension(200, 110));
setLocationRelativeTo(null);
pack();
}
}
thanks in advance!