Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main() {
        Frame frame = new Frame();

        WindowListener listener = new WindowAdapter() {
            public void windowOpened(WindowEvent evt) {
                Frame frame = (Frame) evt.getSource();
                System.out.println(frame.getTitle());
            }

            public void windowClosing(WindowEvent evt) {
                Frame frame = (Frame) evt.getSource();

                System.out.println(frame.getTitle());

            }

            public void windowClosed(WindowEvent evt) {
                Frame frame = (Frame) evt.getSource();
                System.out.println(frame.getTitle());
            }
        };

        frame.addWindowListener(listener);
        frame.setVisible(true);
    }
}