Source Code : Handle JFrame window events

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Handle JFrame window events

    
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);
  }
} 

   
    
    
    
  

Thank with us