Tutorial Tutorial

Step 15: Override the WindowEvent handler in DecoratedFrame

At this point, if you close the application frame from the system menu or the [X] close button, it won't ask you if you want to save your file, even if it is dirty. To fix this, hook up the system close event to the same code that File|Exit uses to ask the user whether to save a dirty file.

Add a method that will override the processWindowEvent() inherited from the DecoratedFrame class. Place it just above the fileExit_actionPerformed event handler.

  /**
   * Override DecoratedFrame's system close handler
   */
  protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      if (okToAbandon()) {
        System.exit(0);
      }
    }
  }
Congratulations, you now have a functional text editor written in JBuilder!

Tutorial Tutorial