I'm looking for clarification about an answer given to an old question: Do something when the close button is clicked on a JFrame
In the answer, Ravindra Gullapalli suggested this code:
import javax.swing.JOptionPane;
/*Some piece of code*/
frame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
if (JOptionPane.showConfirmDialog(frame,
"Are you sure to close this window?", "Really Closing?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION){
System.exit(0);
}
}
});
Firstly, is this the proper way to do this in Netbeans?
Secondly, what is "frame"? (the first word in the 3rd line of code in the answer as well as the first parameter of showConfirmDialog). According to swing API, this should be of type Component. However, when I replaced this with the Title property of my JFrame, I still got a "cannot find symbol" error. Is the Component name different than the JFrame title, and if so where can I find it? In the NetBeans Navigator, it just says [JFrame] and does not display the Component name, unlike all the other Form objects which display and editable Component name next to the type.