What is WindowEvent?
We know whenever a component is interacted by the user, an event is generated. For example, when a button is clicked, the button raises ActionEvent. Similarly now, when the frame is clicked it raises WindowEvent and infact this object is passed as parameter to the seven methods. Handling the event raised by a component is the first and foremost step in event handling. By handling the WindowEvent, the application (here, frame) is closed with System.exit(0).
The above statement terminates the current application; in this case, the frame closes. The exit(0) indicates normal shutdown and any parameter other than 0 (like 1) is abnormal termination; of course, this is operating system dependent.