JOptionPane - JAVA modal dialogue

0

I would like to ask click on an "OK" button ( button_OK ) to ask me if I'm sure to perform "x" action.

If I strike YES - > Code to be made ...

If I strike NO - > The JOptionPane is closed and I return to the window of the same button_OK

Code :

private void button_OKActionPerformed(java.awt.event.ActionEvent evt) {
Conexiones.cargar(valor, entero);
        //Cerramos el JDialog actual.
        dispose();
        //Cargamos el JDialog de compra y lo hacemos visible para interactuar con él.
        Compra c = new Compra(null, true);
        c.setVisible(true);
}

I would like something similar to the closing of a window in Java, whose code is as follows:

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?", 
                        "Salir de la aplicación", JOptionPane.ERROR_MESSAGE) == JOptionPane.ERROR_MESSAGE){
                    System.exit(0);
                }
            }
        });
    
asked by omaza1990 18.01.2017 в 23:43
source

1 answer

0

That problem I already solved (if I'm not wrong with Google's help and I think in a part of StackOverFlow in English and it applies more than everything for JFrames since I use NetBeans), This is the code, you must understand how it works first :
import javax.swing.JOptionPane; int a = 0; a = JOptionPane.showConfirmDialog(null, "Desea salir del sistema?"); if (a == JOptionPane.YES_OPTION) { a = JOptionPane.showConfirmDialog(null, "Realmente estas seguro?"); if (a == JOptionPane.YES_OPTION) { //Codigo de Salida System.exit(0); } }


I hope you understand the code and that it is of great help :), besides, you should look for the documentation of JOptionPane, it is easier and more useful: 3

    
answered by 08.02.2017 в 14:47