I have problem with showing a dialog in Thread.Sleep method here is my code, its not working.

```
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent arg0) {
    JDialog loading = new LoadingDialog();
    loading.setVisible(true);
    try {
      Thread.sleep(6000);
    } catch (Exception e) {
      e.printStackTrace();
    }
    loading.dispose();
  }
});

```

and

```
public class LoadingDialog extends JDialog { 
  public LoadingDialog(){ 
    Toolkit tk = Toolkit.getDefaultToolkit(); 
    Dimension screenSize = tk.getScreenSize(); 
    int screenHeight = screenSize.height; 
    int screenWidth = screenSize.width; 
    setBounds((screenWidth-400)/2, (screenHeight-200)/2, 350, 80);
    getContentPane().setLayout(null);
    setResizable(false); 
    setUndecorated(true); 
    JLabel lblPleaseWaitWhile = new JLabel("Please wait while starting the services."); 
    lblPleaseWaitWhile.setBounds(85, 22, 313, 14); getContentPane().add(lblPleaseWaitWhile); 
    setVisible(true); 
  } 
}

```

Help me to solve this.