When you click the close button in the top right corner the application closes. If you want to do something before the application closes (eg. a dialog with ok and cancel options) or prevent it from closing , you'll have to override the org.openide.modules.ModuleInstall class.
Make a class in your module that extends the org.openide.modules.ModuleInstall class and override the closing() method. Keep in mind that setting the return value of this method to "true" means the application will not be able to close at all.
Next you have to tell your module to load this new class by adding a reference to your Manifest file : e.g. "OpenIDE-Module-Install: org/netbeans/modules/java/JavaModule.class" where "JavaModule.class" should be the name of your class.
Source: NetBeans FAQ