Java Swing Tutorial - Java WindowEvent(Window source, int id, int oldState, int newState) Constructor








Syntax

WindowEvent(Window source, int id, int oldState, int newState) constructor from WindowEvent has the following syntax.

public WindowEvent(Window source,   int id,   int oldState,   int newState)

Example

In the following code shows how to use WindowEvent.WindowEvent(Window source, int id, int oldState, int newState) constructor.

import java.awt.event.WindowEvent;
/* www  . j av a 2s. co  m*/
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK);
  }

  protected void processWindowEvent(WindowEvent e) {
    WindowEvent newEvent = new WindowEvent(this,
       WindowEvent.WINDOW_FIRST,
       WindowEvent.WINDOW_CLOSED,
       WindowEvent.WINDOW_ACTIVATED);
    
    super.processWindowEvent(e); // Pass on the event
  }

  public static void main(String[] a) {
    Main window = new Main();
    window.setBounds(30, 30, 300, 300);
    window.setVisible(true);
  }
}