You are here: Home / Topics / Program to use Window Event in Java

Program to use Window Event in Java

Filed under: Java on 2023-10-19 07:07:54

//  Program to use Window Event.

import java.awt.*;
import java.awt.event.*;

public class WindowEventDemo extends Frame implements WindowListener
{
public WindowEventDemo()
{
 addWindowListener( this );
 setSize( 250, 150 );
 setVisible( true );
}

public void windowOpened( WindowEvent we )
{
 System.out.println( "Window Opened" );
}

public void windowIconified( WindowEvent we )
{
 System.out.println( "Window Iconified" );
}

public void windowDeiconified( WindowEvent we )
{
 System.out.println( "Window Deiconified" );
}
   
public void windowActivated( WindowEvent we )
{
 System.out.println( "Window Activated" );
}
   
public void windowDeactivated( WindowEvent we )
{
 System.out.println( "Window Deactivated" );
}
   
public void windowClosing( WindowEvent we )
{
 dispose();
 System.out.println( "Window Closing" );
}
   
public void windowClosed( WindowEvent we )
{
 System.out.println( "Window Closed" );
 System.exit( 0 );
}

public static void main( String[ ] args )
{
 Frame f = new WindowEventDemo();
}
}

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.