Java Swing How to - Open a JOptionPane by another JOptionPane








Question

We would like to know how to open a JOptionPane by another JOptionPane.

Answer

import javax.swing.JOptionPane;
/*  w  ww.  j a  v  a2 s  . c  om*/
public class Main {
  public static void main(String args[]) {

    int choose = JOptionPane.showConfirmDialog(null, "Open Dialog  ??");

    if (choose == JOptionPane.YES_OPTION) {
      JOptionPane.showMessageDialog(null, "You Clicked Yes !!");
    } else if (choose == JOptionPane.NO_OPTION) {
      JOptionPane.showMessageDialog(null, "You Clicked NO");
    }
  }
}