Possible Duplicate:
Call a method when application closes
I want to call a method just before I close my java application using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); I have tried WindowListener with windowClosed/windowsClosing and it doesn't work. it looks something like this
public class exampleFrame JFrame implements{
public exampleFrame (){
this.addWindowListener(new windowAction());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class windowAction implements WindowListener{
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent e) {
System.out.prinln("window closed")
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.out.prinln("window closing")
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
}
}