Advertisement
Method | Description |
---|---|
public Window getWindow() | Returns the window which triggered the WindowEvent. |
public int getNewState() | Returns the new state of the window. |
Method | Description |
---|---|
public void windowOpened(WindowEvent e) | This method is called when a window is opened for the first time. |
public void windowActivated(WindowEvent e) | This method is called when a window shows up on screen. |
public void windowDeactivated(WindowEvent e) | This method is called is no longer the window in use or active. |
public void windowIconified(WindowEvent e) | This method is called when a window is changed from a normal to a minimized state. |
public void windowDeiconified(WindowEvent e) | This method is called when a window is brought up on the screen from a minimized state. |
public void windowClosing(WindowEvent ke) | This method is called a user clicks on the (x) icon to close the window. |
public void windowClosed(WindowEvent e) | This method is called when a window has been closed. |
Method | Description |
---|---|
public void addWindowListener(ItemListener object) | where object is an object of the class that has implemented Windowistener interface. Doing this, registers the class to listen and respond to WindowEvent. |
Advertisement
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WindowEx1 implements WindowListener
{
Label label1;
Frame frame;
WindowEx1()
{
frame = new Frame("Handling KeyEvent");
label1= new Label("-See window events -", Label.CENTER);
frame.setLayout(new FlowLayout());
frame.add(label1);
//Registering class WindowEx1 to catch and respond to window events
frame.addWindowListener(this);
frame.setSize(340,200);
frame.setVisible(true);
}
public void windowActivated(WindowEvent we)
{
System.out.println("Window Activated");
}
public void windowClosed(WindowEvent we)
{
System.out.println("Window Closed");
}
public void windowClosing(WindowEvent we)
{
frame.dispose();
System.out.println("Window Closing");
}
public void windowDeactivated(WindowEvent we)
{
System.out.println("Window Deactivated");
}
public void windowDeiconified(WindowEvent we)
{
System.out.println("Window Deiconified");
}
public void windowIconified(WindowEvent we)
{
System.out.println("Window Iconified/minimized");
}
public void windowOpened(WindowEvent e)
{
System.out.println("Window Opened for the first time");
}
public static void main(String... ar)
{
new WindowEx1();
}
}
Window Activated
Window Opened for the first time
Window Iconified/minimized
Window Deactivated
Window Activated
Window Closing
Window Deactivated
Window Closed
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement