Parameter meaning and usage example of setdefaultcloseoperation in Java swing JFrame framework class

This article describes the meaning and usage of the setdefaultcloseoperation parameter in the Java swing JFrame framework class. Share with you for your reference, as follows:

Let's take a look at an example (an empty Java window):

A form is generated from the program running result, and the running effect is as follows:

Interested friends can modify the corresponding method parameters in turn according to the comments of the program code to see the effect.

Let's look at the setdefaultcloseoperation method:

Setdefaultcloseoperation (int operation): sets the default operation to be performed when the user initiates "close" on this form. The parameters in the method are explained as follows:

① Is' 0 'or do_ NOTHING_ ON_ Close: (defined in windowconstants): do not perform any operation; the program is required to process the operation in the windowclosing method of the registered windowlistener object. For example, the instance program code is changed to f.setdefaultcloseoperation (F. do_noting_on_close); Or f.setdefaultcloseoperation (0), and then check the effect. You can find that the window cannot be closed. The following is the same test method, which will not be explained.

② Is "1" or hide_ ON_ Close automatically hides any registered windowlistener object after it is called. At this time, the program is not closed, but the program interface is hidden. You can open the task manager, You can see a process called "Java. Exe" (if you debug and run multiple Java programs, you will see multiple "Java. Exe" processes). If you test the program with EDITPLUS at this time, you will find that when you click the close button of the window to close the window, you cannot debug the program again because the program thread is not closed. Close java.exe in the task manager (if there are multiple "Java. Exe" processes, close them first, and then test the problem.) EDITPLUS can recompile the modified program after the foundation.

③ Is' 2 'or dispose_ ON_ Close automatically hides and releases any registered windowlistener object after it is called. However, continuing to run the application frees up the resources occupied in the form.

④ Exit for "3"_ ON_ Close (defined in JFrame): use the system exit method to exit the application. Only used in the application. The application ended.

⑤ By default, this value is set to hide_ ON_ CLOSE。 When f.setdefaultcloseoperation (f.exit_on_close) in the instance is commented out; Statement and f.setdefaultcloseoperation (F. hide_on_close); Or F. setdefaultcloseoperation (1); Same.

Readers interested in more Java related content can view the topics on this site: Java data structure and algorithm tutorial, @l)u 419)u 1@, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>