简体   繁体   中英

JAVA GUI Closing Application Dialog

Details : I have a JAVA application that takes some time to shutdown. There is a call to close a port, that takes a really long time. I want to add a dialog box that indicates to the user that the application is shutting down. Normally, I would create a dialog box, start a thread to do long work and close dialog, then display the dialog. Once the work is done, the dialog would be close. This does not work for shutting down an application because it seems the window listener closes all windows (kind of makes sense, it supposed to do that). I'm not sure a way around this.

Code:

public void windowClosing(WindowEvent we)
{
    shutDown();
}

public void shutdown()
{
  final JDialog dialog = createDialog();
  Thread t = new Thread
  {
      public void run()
      {
         saveProperties();
         ClosePort();
         dialog.setVisible(false);
         System.exit(0);         
      }
   };
   t.start();
   dialog.setVisible(true);  
}
t.setDaemon(true);

因为守护线程即使其余部分都消失了也仍然保持活动状态。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM