Java tutorial
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class Main extends JFrame { public Main() { setSize(300, 300); setTitle("Window Listener"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { System.out.println("Window Opened Event"); } public void windowClosing(WindowEvent e) { System.out.println("Window Closing Event"); } public void windowClosed(WindowEvent e) { System.out.println("Window Close Event"); } public void windowIconified(WindowEvent e) { System.out.println("Window Iconified Event"); } public void windowDeiconified(WindowEvent e) { System.out.println("Window Deiconified Event"); } public void windowActivated(WindowEvent e) { System.out.println("Window Activated Event"); } public void windowDeactivated(WindowEvent e) { System.out.println("Window Deactivated Event"); } public void windowStateChanged(WindowEvent e) { System.out.println("Window State Changed Event"); } public void windowGainedFocus(WindowEvent e) { System.out.println("Window Gained Focus Event"); } public void windowLostFocus(WindowEvent e) { System.out.println("Window Lost Focus Event"); } }); } public static void main(String[] args) { new Main().setVisible(true); } }