Monitoring specific AWT events

The following example monitors Window events and Key events and prints them out.

Main.java:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
class Main extends JFrame
{
   public Main() {
      Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
         public void eventDispatched(AWTEvent e) {
            System.out.println(e);
         }
      }, AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK );
   }
 
   public static void main(String[] args) {
      Main main = new Main();
      main.setDefaultCloseOperation( EXIT_ON_CLOSE );
      main.setSize(200, 200);
      main.setVisible(true);
   }
}