(This is original) JFRAME closes, Close Frame, prompt window

xiaoxiao2021-03-06  40

When I started, I just wanted to write a JFrame, let him prompt when it was closed, so he rewritten, Windowadapter's WindowClosing method, but failed, the window was finally closed, no matter what you really want to close, so write The following procedure, found that setDefaultcloseOperation (windowconstants.do_nothing_on_close) makes my program bad, he automatically makes the closed action, JFrame and Frame are different, so let's setdefaultcloseOperation (windowconstants.do_nothing_on_close), then rewrote Good make it.

// This is a test setDefaultCloseOperationWindowConstants.DO_NOTHING_ON_CLOSE) of import java.awt.event *;. Import javax.swing *;. Public class tryWindowAdapter extends JFrame {public tryWindowAdapter () {super ( "try to close"); this.setSize ( 400,400); this.setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE); this.addWindowListener (new WindowAdapter () {public void windowClosing (WindowEvent e) {System.out.println ( "haha"); System.exit (0);}}) This.setvisible (TRUE); public static void main (string args []) {new trywindowadapter ();}}

// Tips when closed

Import java.awt. *; import java.awt.event. *; import javax.swing. *; // Import javax.swing.event. *;

public class tryWindowAdapter extends JFrame {public tryWindowAdapter () {super ( "try to close"); this.setSize (400,400); this.setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE); this.addWindowListener (new WindowAdapter () {public void windowClosing (WindowEvent e) {IF (JOPANE.OK_OPTION == JOPANE.SHOWCONFIRMDIALOG (() E.GETSOURO (), "Really Quit?")) {system.exit (0);} else return;}}; this.setVisible PUBLIC Static void Main (String Args []) {new trywindowadapter ();}}

转载请注明原文地址:https://www.9cbs.com/read-61578.html

New Post(0)