This is an example of the old calculator project in which I had added a splash screen
this is Calculator class(Application Window) here I have made the object of Splash Class
and set that visible true.
You have to remove the following 2 lines from your code
EventQueue.invokeLater(new Runnable() {
public void run() {
Rest I had also added a progress bar as mentioned below.
public static void main(String[] args) {
try {
Splash splash = new Splash();
Calculator window = new Calculator();
splash.setVisible(true);
for(int i = 0;i <= 100; i++) {
Thread.sleep(i);
splash.setProgressBar(i);
splash.setLblpercentage(Integer.toString(i)+"%");
if (i == 100) {
splash.dispose();
window.frame.setVisible(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
Make sure to remove the main method from the JFrame of the splash screen.
Also, make components of frame static to access them from the main class and also generate getter and setters.
private static JProgressBar progressBar;
private static JPanel frame;
private static JLabel lblpercentage;
public static JLabel getLblpercentage() {
return lblpercentage;
}
public static void setLblpercentage(JLabel lblpercentage) {
Splash.lblpercentage = lblpercentage;
}
public static JProgressBar getProgressBar() {
return progressBar;
}
public static void setProgressBar(JProgressBar progressBar) {
Splash.progressBar = progressBar;
}