I don’t get how can I employ this code:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
to close the program with the x button.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need the line
Because the default behaviour for the JFrame when you press the X button is the equivalent to
So almost all the times you’ll need to add that line manually when creating your JFrame
I am currently referring to constants in
WindowConstantslikeWindowConstants.EXIT_ON_CLOSEinstead of the same constants declared directly inJFrameas the prior reflect better the intent.