2011-11-29 124 views
1

我需要在按鈕單擊時顯示啓動屏幕。當我點擊按鈕時,飛濺必須可見,我做了一些在後臺運行的進程。後臺進程完成後,飛濺必須消失。我使用了下面的代碼,但飛濺不可見。當我在主類中使用相同的代碼時,它可以工作。addActionListener中的初始屏幕

btnClickToMove.addActionListener(new ActionListener() { 

       public void actionPerformed(ActionEvent e) { 
    JWindow window = new JWindow(); 
        window.getContentPane().add(
            new JLabel("Loading JFrame...", SwingConstants.CENTER)); 
        window.setBounds(200, 200, 200, 100); 
        window.setVisible(true); 
        try { 
          Thread.sleep(5000); 
        } catch (InterruptedException e) { 
          e.printStackTrace(); 
        } 

    // my process which runs on background....... 

     window.setVisible(false); 
     window.dispose(); 
     } 
      }); 
+0

'的Thread.sleep(5000);'不要那樣做。如果需要,可以使用單次(Swing)定時器,但不要阻塞EDT。 –

回答