Answer:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
Explanation:
JFrame is the swing class that is used to display a frame object. The JFrame display contains an X button on the top right position which is used to turn off the display of the frame. However if we want to terminate the program on pressing the X button, we need to update the DefaultCloseOperation for the frame. JFrame provides a method ''setDefaultCloseOperation' for this purpose. When this method is called with the argument JFrame.EXIT_ON_CLOSE , it will cause the program to exit when the close button is pressed.