Java tutorial
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JDialog; public class Main extends JDialog { public Main() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("closing..."); } }); } public static void main(String[] args) { Main m = new Main(); m.setVisible(true); } }