Java JFrame set default close operation to do-nothing-on-exit
import java.awt.FlowLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class Main extends JFrame { public Main() { super("JButton"); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setLayout(new FlowLayout()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.out.println("about to close"); }/* w ww.j a va 2 s . c om*/ }); } public static void main(String[] args) { Main frame = new Main(); frame.pack(); frame.setVisible(true); } }