import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JOptionPane; public class GridWindowClosedEvent extends WindowAdapter { private GridWindow window; public GridWindowClosedEvent(GridWindow window) { this.window = window; } @Override public void windowClosing(WindowEvent event) { int result = JOptionPane.showConfirmDialog(this.window, "Are you sure you want to close this window?", "Close current window", JOptionPane.YES_NO_OPTION); if(result == JOptionPane.YES_OPTION) this.window.dispose(); } }