0

I have created two JFrames.
1. A Splash Screen
2. A Main Window

I need to display the Splash Screen 1st and then while the splash screen is displayed, the Main Windows object gets created. (it takes few seconds to create that object as it's a complex window.)

I have used a JXBusyLabel on the Splash Screen and it is set to busy by default.

This is my main method.

public static void main(String[] args) {

        SwingWorker sw = new SwingWorker() {

            @Override
            protected Boolean doInBackground() throws Exception {
                SplashScreen sp = new SplashScreen();
                sp.setVisible(true);
                return true;
            }
        };
        sw.execute();

        Thread t1 = new Thread() {

            public void run() {
                try {
                    /* some stuff here */
                    MainFrame mf = new MainFrame(); // (A)
                    mf.setVisible(true);
                } catch Exception ex) {
                    /* Logger */
                }
            }
        };

        t1.start();

}

When I run this, the splash screen appears and the busy label works fine for a while. And then it freezes, as the MainFrame gets created (in line (A) ).

I tried to use a normal thread to show the SplashScreen too. But the result was the same.

What am I doing wrong here??

4

0 回答 0