6
    mainFrame.addWindowListener(new WindowListener() {

        @Override
        public void windowClosing(WindowEvent e) {
            if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) {
                return;
            }
            System.exit(-1);
        }

        @Override 
        public void windowOpened(WindowEvent e) {}

        @Override 
        public void windowClosed(WindowEvent e) {}

        @Override 
        public void windowIconified(WindowEvent e) {}

        @Override 
        public void windowDeiconified(WindowEvent e) {}

        @Override 
        public void windowActivated(WindowEvent e) {}

        @Override 
        public void windowDeactivated(WindowEvent e) {}

    });

There is my code, is it possible since I only use the windowClosing method to remove all the other in my case, useless methods so it takes less space?

Example

    mainFrame.addWindowListener(new WindowListener() {

        @Override
        public void windowClosing(WindowEvent e) {
            if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) {
                return;
            }
            System.exit(-1);
        }

    });

Is it possible?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jonathan Beaudoin
  • 2,158
  • 4
  • 27
  • 63

1 Answers1

13

There is a default implementation of WindowListener called WindowAdapter which allows you to override the methods you really want to use

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 3
    This is also true for other listeners like `MouseListener`/`MouseAdapter`, `MouseMotionListener`/`MouseMotionAdapter`, `KeyListener`/`KeyAdapter` etc.. – Håvard Geithus Feb 03 '14 at 22:49