WindowEvent


Prev Tutorial Next Tutorial

Event Handling for Window

Event handling for window you need WindowEvent and WindowListener interface.

Event classListener Interface
WindowEventWindowListener

Method (abstract method)

public void windowOpened(WindowEvent e): This method will be execute if the window is open.

public void windowClosing(WindowEvent e): This method will be execute if the window is going to be closed.

public void windowClosed(WindowEvent e): This method will be execute if the window is already closed.

public void windowActivate(WindowEvent e): This method will be execute if the window is in selected state.

public void windowDeactivated(WindowEvent e): This method will be execute if the window is not in selected state.

Example of ItemEvent

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

class A extends Frame 
{
A()
{
setTitle("Insurance Managment Sysytem");
setBackground(Color.cyan);
setLayout(null);
   
 addWindowListener(new WindowAdapter()
{
  public void windowClosing(WindowEvent we)
{
  System.exit(0);
  }
  });

setSize(500,300);
setVisible(true);
}  //constructor
}  // class

class WindowEventEx
{
public static void main(String s[])
{
A obj=new A();
}
}	

Download code Click

window close example
Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements