Pessoal, estava usando o WindowEvent e o WindowListener para criar uma ação onde quando a pessoa fosse fechar o JFrame lhe fosse questionado se a pessoa queria mesmo fechar.
Assim:
JFrame.addWindowListener(new java.awt.event.WindowAdapter(){
public void windowClosing(java.awt.event.WindowEvent e){
if(e.getID() == WindowEvent.WINDOW_CLOSING){
int selectedOption = JOptionPane.showConfirmDialog(null, "Tem certeza que quer fechar?",
"Fechar",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(selectedOption == JOptionPane.OK_OPTION){
System.exit(0);
}
}
}
});
Porem apareceu um erro dizendo:
“non-static method addWindowListener(WindowListener) cannot be referenced from a static context”
Alguém poderia me ajudar?