I am trying to create a loading screen for my program so it will display the loading screen while loading the main screen or while executing a particular task. I tried to use a JDialog as the loading screen but for some reason, once the loading screen dialog opens up, it doesnt let the main program run its own job. How do I make them work both at the same time?
Here is the code for my loading screen:
public class FrmLoading extends JDialog {
private static FrmLoading loading;
public FrmLoading(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(null);
}
public static void startAnimation(){
loading = new frmLoading(null, true);
loading.setVisible(true);
}
public static void stopAnimation(){
loading.dispose();
}
private void initComponents(){
//build the Dialog
}
}
this is how I use it:
private void login(){
FrmLoading.startAnimation();
//open main program
}
...
private void mainStart(){
//load contents
FrmLoading.stopAnimation();
}
I know that there is a loadingscreen default to java swing but I dont want to use it, I want the animation I made.