0% found this document useful (0 votes)
5 views3 pages

Java WindowListener Interface Overview

The WindowListener Interface in Java, found in the java.awt.event package, is used to handle changes in the state of a window. It includes seven methods for various window events such as activation, closing, and opening. An example implementation is provided, demonstrating how to create a window and respond to these events.

Uploaded by

Tejas Shukla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java WindowListener Interface Overview

The WindowListener Interface in Java, found in the java.awt.event package, is used to handle changes in the state of a window. It includes seven methods for various window events such as activation, closing, and opening. An example implementation is provided, demonstrating how to create a window and respond to these events.

Uploaded by

Tejas Shukla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Dr.

Bharti Sharma

WindowListener Interface

 In Java, WindowListener Interface is under [Link]


package.
 This interface is used when the state of the window is
changed.

It has 7 methods which are as following:

1. public abstract void windowActivated(WindowEvent e);

2. public abstract void windowClosed(WindowEvent e);

3. public abstract void windowClosing(WindowEvent e);

4. public abstract void windowDeactivated(WindowEvent e);

5. public abstract void windowDeiconified(WindowEvent e);

6. public abstract void windowIconified(WindowEvent e);

7. public abstract void windowOpened(WindowEvent e);

Example:

In this example, we are handling windows events like: window open,


close etc.

import [Link].*;
import [Link];
import [Link];
class WindowDemo1 extends Frame implements
WindowListener
{
WindowDemo1()
{
addWindowListener(this);
Dr. Bharti Sharma

setSize(500,500);
setLayout(null);
setVisible(true);
}

public static void main(String[] args)


{
new WindowDemo1();
}
public void windowActivated(WindowEvent arg0)
{
[Link]("Window ==> activated");
}
public void windowClosed(WindowEvent arg0)
{
[Link]("Window ==> closed");
}
public void windowClosing(WindowEvent arg0)
{
[Link]("Window ==> closing");
dispose();
}
public void windowDeactivated(WindowEvent arg0)
{
[Link]("Window ==>
deactivated");
}
public void windowDeiconified(WindowEvent
arg0)
{
[Link]("Window ==>deiconified");
}
public void windowIconified(WindowEvent arg0)
{
[Link]("Window ==>iconified");
}
public void windowOpened(WindowEvent arg0)
{
[Link]("Window ==> opened");
}
Dr. Bharti Sharma

You might also like