在关闭JDialog窗口时进行确认

I want to have a confirmation when closing a JDialog, I do it the same way as if it were a JFrame, but in this case if I press "NO", it closes me the same way.

In JFrame files it works for me but in JDialog, no.

为什么?

码:

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent evt){
            if (JOptionPane.showConfirmDialog(rootPane, "¿Desea salir de la aplicación?", 
                    "Gestor de clientes", JOptionPane.ERROR_MESSAGE) == JOptionPane.ERROR_MESSAGE){
                System.exit(0);
            }
        }
    });