Hi Guys,
I have a main program which calls a JFrame to get User information, If a user press submit I am storing the information in POJO and getting it into Main program.
If User clicks on Exit, I want to dispose the JFrame and want to exit the main program as well after executing one logging statement in main method.
If I use -
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
and
this.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
e.getWindow().dispose();
}
});
all the Threads exit immediately and I am not able to execute logging statments in main method.
If I use-
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
e.getWindow().dispose();
}
});
My main method execute those logging statments but it never exit, It stay silent after executing all the statements.
If I use this -
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
Thread.currentThread.interrupt();
}
});
Everything works fine. But is it the correct way of doing this?
enter code here