how do you do when you click on the NO option of a confirmdialog stay there in a form jframe of netbeasn?

-1

How to do when you click on the NO option of a confirmdialog, stay there in a form jframe of netbeasn?

private void jButton3MouseClicked( java.awt.event.MouseEvent evt ) {
    int ax = JOptionPane.showConfirmDialog(
        null, 
        "Esta Seguro Que Desea Salir?"
    ); 

    if ( ax == JOptionPane.YES_NO_OPTION ) {
        JOptionPane.showMessageDialog(
            null, 
            "Hasta Pronto,Que Tengas Un Buen Dia."
        );
    }
    System.exit(0);

    if ( ax == JOptionPane.NO_OPTION ) {
        JOptionPane.showMessageDialog(
            null, 
            "Has seleccionado NO."
        );
    }
}
    
asked by Jhosser Becerra F. 22.05.2017 в 22:40
source

1 answer

1

In the following example you can see how the value returned by the window is stored in the property "res", of type integer:

package pruebas;
import javax.swing.JOptionPane;

public class TestConfirmDialog {

public static void main(String[] args) {

    int res = JOptionPane.showConfirmDialog(
        null, 
        "¿Quieres continuar?", 
        "Confirm",
        JOptionPane.YES_NO_OPTION, 
        JOptionPane.QUESTION_MESSAGE
    );
    if ( res == JOptionPane.NO_OPTION ) {
      System.out.println( "Seleccionaste NO" );

    } else if (res == JOptionPane.YES_OPTION) {
      System.out.println( "Seleccionaste SI" );

    } else if (res == JOptionPane.CLOSED_OPTION) {
      System.out.println( "Cerraste la ventana" );
    }

    System.out.println( "Valor devuelto: " + res );
  }

} //class
  

A couple of pages that develop the theme (in English):

     

link    link

    
answered by 23.05.2017 в 00:29