WindowEvent
Advertisements
Event Handling for Window
Event handling for window you need WindowEvent and WindowListener interface.
Event class | Listener Interface |
---|---|
WindowEvent | WindowListener |
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
Google Advertisment