Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing- close whole application when a dialog is cancelled

I have a JFrame which on instantiation calls a custom JDialog(Login). If login is successful i want that jFrame to be visible. And if user presses escape/cancel on that login dialog the whole application should be closed.

How can i do so...

Currently if i dispose dialog the jFrame gets visible.

like image 274
Shashank Degloorkar Avatar asked Feb 21 '23 03:02

Shashank Degloorkar


1 Answers

Assuming you have access to your JFrame via a frame variable, you can simply call:

frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));

It is probably better than calling a System.exit() as it will enable you to run some cleanup code if you have registered a window closing listener to your frame.

like image 81
assylias Avatar answered Mar 06 '23 00:03

assylias