static AutoCloseable tempOnFrameClose(JFrame f, Runnable r) { if (f == null || r == null) null; ret swing(-> { var listener = new WindowAdapter { public void windowClosing(WindowEvent e) { pcall-messagebox { r.run(); } } }; f.addWindowListener(listener); ret -> swing { f.removeWindowListener(listener); }; }); }