When the user wants to exit the application, I use a jcustomdialog ask if he really wants to exit. If the user press buton cancel , i close jcustomdialog but if the user press acept button, then I must finish.
other languages I have used application.terminate
Or other idea for exit whit ask the user if want