java - Swing addWindowFocusListener -


I have a simple Java swing application, I want to first confirm the user from the main window.

My code is:

  package client_interface; Import java.awt.EventQueue; Import java.awt.GraphicsDevice; Import java.awt.GraphicsEnvironment; Import java.awt.Rectangle; Import java.awt.event.WindowAdapter; Import java.awt.event.WindowEvent; Import javax.swing.JFrame; Import javax.swing.JOptionPane; Public class manwindows {Private Jeffrey Frame; Public Static Zero Main (string [] algens) {EventQueue.invokeLater (New Runnabal) (Public Zero Run) {try {mainwindow window = new mainwindow}; Window.frame.setVisible (true);} catch (exception e) {E.printStackTrace ();}}}); } Public manwindows () {start (); } Private Zero Setframes (GeFame Frame) {Graphics Device GD = Graphics Environment. Galaxy Graphics Environment () GetDefaultScreenDevice (); Int width = gd.getDisplayMode (). GetWidth (); Int height = gd.getDisplayMode (). GetHeight (); Frame Setbound (new rectangle (width / 4, height / 4, width / 2, height / 2)); //frame.setExtendedState (JFrame.MAXIMIZED_BOTH); } Private Zero Start () {frame = New JFrame ("Test"); SetFrameSize (frame); Frame.addWindowFocusListener (New Window Adapter) {Public Zero Window Closing (WindowEnd E) {If ShowPan Show Show Configurable Dialog (frame, "Do you want to close this window?", "Really closing?" , Joppenpen.Yes, NOO-OPTN, JOSPNEPN QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {System.exit (0);}}}); }}  

But that frame looks. AddWindowFocusListener does not work.

Please show me the correct way to add event windows. Close my frame

change

  frame. AddWindowFocusListener (new WindowAdapter () {  

with

  frame.and window listener (new window editor () { 

first one WindowFocusListener is said to be that when the window either loses or loses.


Comments