Before the explanation about WindowAdapter. Just to let you know that those lines of codes may also be replaced with this one and do the exact same thing:
PHP Code:
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
And I hope that code is more readable than the one that you have (although it's actually better to use the one what you have because it's more explicit) "Better" in the sense that you have much more control to what do you want your GUI to do when the close "X" button is pressed.. lol.. I played with this around with my friend by poping up another window each time it's pressed!!!
Anyways, WindowAdapter and WindowListener are basically (almost) the same thing with actionListener that you have with other objects such as buttons. When you say
PHP Code:
WindowListener l = new WindowAdapter() {
}
that means that you're calling the instance of
WindowListener (the action listener for the GUI's window). As you may realize, Java divided your GUI into 3 parts: Window, Frames, and Panel. The Window will be the outer most of your GUI, the Frame will be the one that's within the Window (the content), and the Panel will be what is within the Frames (you can add JPanel within Frame).
WindowAdapter however is one method that must be overridden when you called WindowListener (It's an abstract method). And WindowAdapter class has a method called windowClosing that takes a WindowEvent.
PHP Code:
System.exit(0); // you can change "0" to whatever you wanted
This code is the one that's going to close the System process of the JVM. Be careful with this when you run 2 Java program at the same time, because both of them will be closed when this function is called. It will basically turned off the JVM process.
Please note that I haven't personally research that deep to these matters, so I can't give you more detailed explanation than what I understood. Hopefully this would help
