Determining When a Frame or Window Is Opened or Closed

// Create the frame Frame frame = new Frame(); // Create a listener for window events WindowListener listener = new WindowAdapter() { // This method is called after a window has been opened public void windowOpened(WindowEvent evt) { Frame frame = (Frame)evt.getSource(); } // This method is called when the user clicks the close button public void windowClosing(WindowEvent evt) { Frame frame = (Frame)evt.getSource(); // By default, nothing happens when the user clicks the close button. // To close the frame, see Hiding a Frame When Its Close Button Is Clicked } // This method is called after a window is closed public void windowClosed(WindowEvent evt) { Frame frame = (Frame)evt.getSource(); } }; // Register the listener with the frame frame.addWindowListener(listener);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.