Closing our application
One thing that's kind of annoying is that our program is continuing to run even after we close the associated GUI. That's a little silly. When I press the close button on the NetBeans GUI, NetBeans closes itself and stops running as a process on my system. We can instruct our frame to terminate the associated process using its setDefaultCloseOperation method. This method has the return type void and takes an integer as a value. This integer is an enumerator, and there's lots of options available to us. All of these options are statically declared by the JFrame class, and the one we're probably looking for is EXIT_ON_CLOSE, which will exit our application when we close our window. Build and run the program, and terminate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access