I am creating a program where the contents of a directory is being copied to another directory. Before the copy process commences I am trying to open a second Jframe to tell the user that the copying is in progress. The issue is that the second JFrame does not load completely until the copy progress is completed. Does anyone know of a way to load the second frame completely before starting the copying?
First Frame Code
public class First {
private JFrame frmFirstFrame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
First window = new First();
window.frmFirstFrame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public First() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmFirstFrame = new JFrame();
frmFirstFrame.setTitle("First Frame");
frmFirstFrame.setBounds(100, 100, 450, 300);
frmFirstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmFirstFrame.getContentPane().setLayout(null);
JButton btnCopy = new JButton("Copy");
btnCopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String source = "D:\\";
String destination = "D:\\test\\";
Second second = new Second();
second.setVisible(true);
File s = new File (source);
File d = new File (destination);
try {
FileUtils.copyDirectory(s, d);
//second.setVisible(false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btnCopy.setBounds(184, 111, 89, 23);
frmFirstFrame.getContentPane().add(btnCopy);
}}
Second Frame Code
public class Second extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Second frame = new Second();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Second() {
setTitle("Second Frame");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblCopyCompleted = new JLabel("Copy in Progress...");
lblCopyCompleted.setBounds(76, 70, 217, 37);
contentPane.add(lblCopyCompleted);
}
}
This is what I am getting during the copy progress.
It should look like this during copying.