import javax.swing.*;
import java.awt.event.*;
public class Test {
Test() {
JFrame f=new JFrame("CloseIt");
f.setVisible(true);
f.setSize(400,200);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e)
{
System.out.print("In Windowclosing opr");
f.dispose();
}
});
}
public static void main(String arg[]) {
Test t=new Test();
}
}
I actually wanted to ask the user whether he wants to save the file before closing it.
But whenever I close the frame (cross button), nothing happens.
windowClosing() is not even getting called.
You named your method
WindowClosing().The method that get's called is however
windowClosing().The best recommendation is to annotate your methods with
@Overrideso that the compiler knows that you want to override a method and can produce an error message if your method doesn't override a superclass method: