Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for Swing GUI to close before continuing

I am writing an app that requires the user to enter some data into a Swing GUI which the app will then use. After the user enters the data, there is no longer any need for the GUI as the app will then write some data to files.

The General idea is this:

launchGui();
closeGui();
continueWithComputation();

I understand that Swing uses a few threads in the background which I understand is why the program doesn't block until the GUI is closed.

Is it possible in any way to wait for the GUI to close (single JFrame closed with dispose()) before continuing with continueWithComputation()?

like image 630
apatrick Avatar asked Feb 20 '23 06:02

apatrick


2 Answers

Wait for Swing GUI to close before continuing

Use a modal dialog. See the following for further details:

  • How to Make Dialogs
  • How to Use Modality in Dialogs
like image 135
Andrew Thompson Avatar answered Mar 05 '23 16:03

Andrew Thompson


Is it possible in any way to wait for the GUI to close (single JFrame closed with dispose()) before continuing with continueWithComputation()?

  • user actions add WindowListener

  • from code to call JFrame#setVisible(false), then you can running continueWithComputation(), you have to close this JVM by System.exit(0), otherwise stays in PC's RAM untill restarted or power-off

like image 29
mKorbel Avatar answered Mar 05 '23 17:03

mKorbel