WindowTest.java Source code

Java tutorial

Introduction

Here is the source code for WindowTest.java

Source

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class WindowTest {
    public static void main(String args[]) {
        JFrame frame = new JFrame("Window Listener");
        WindowListener listener = new WindowListener() {
            public void windowActivated(WindowEvent w) {
                System.out.println(w);
            }

            public void windowClosed(WindowEvent w) {
                System.out.println(w);
            }

            public void windowClosing(WindowEvent w) {
                System.out.println(w);
                System.exit(0);
            }

            public void windowDeactivated(WindowEvent w) {
                System.out.println(w);
            }

            public void windowDeiconified(WindowEvent w) {
                System.out.println(w);
            }

            public void windowIconified(WindowEvent w) {
                System.out.println(w);
            }

            public void windowOpened(WindowEvent w) {
                System.out.println(w);
            }
        };
        frame.addWindowListener(listener);
        frame.setSize(300, 300);
        frame.show();
    }
}