title: How do I check if a file is saved when the user tries to close the window button?
body: <p>I have a couple of classes but I am only posting this Main class I have. Most of this code was taken from my professor's sample program. My problem is I want to run a check ONCE the window button is closed. The 'check' is going to see if a Boolean variable 'saved' from another class is True or False, and act accordingly. THEN, close the window. So far I have this, but I am getting an error from the JFrameL. How do I use the WindowClosing method from another class? I see that I am not supposed to call it on its own?</p>
  
  <pre><code>import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  
  
  public class Main {
  
  public static JFrameL frame;
  
  public static void main(String[] args) {
      // Create a window.
      frame  = new JFrameL("Checking Account Actions");
  
      // Set the size of the window.
      frame.setSize(450, 350);
      frame.setAlwaysOnTop(true);
  
      // Specify what happens when the close button is clicked.
      frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  
      CheckingAccountActions panel = new CheckingAccountActions();
      frame.getContentPane().add(panel);
      frame.pack();
  
      // Display the window
      frame.setVisible(true);
  
  }
  
  public class JFrameL extends JFrame {
  
      public JFrameL(String title) {
          super(title);
          FrameListener listener = new FrameListener();
          addWindowListener(listener);
      }
  
      private class FrameListener extends WindowAdapter {
  
          public void windowClosing(WindowEvent e) {
              System.out.println("WindowListener method called: windowClosed.");
              if(!CheckingAccountActions.saved) {
                  String  message = "The data in the application is not saved.\n"
                                  + "Would you like to save it before exiting the application?";
                  int confirm = JOptionPane.showConfirmDialog (null, message);
  
                  if (confirm == JOptionPane.YES_OPTION)
                      CheckingAccountActions.chooseFile(2);
              }
              Main.frame.setVisible(false);
              System.exit(0);
          }
      }
  }
  
   }
  </code></pre>
  
  <p>Error message I am receiving on line 2 from main(): </p>
  
  <p>"No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main)."</p>