title: JOptionPane handling ok, cancel and x button
body: <p>There is one problem I am facing with my JOptionPane
  if I don't key in anything,no matter what I press(the ok,cancel or the x button(the top right button in the JOptionPane)), it will prompt me until the I key in a positive value. but I only want the prompt to happen when i pressed ok.</p>
  
  <p>If I click on cancel or the x button(the top right button in the JOptionPane), it will close the JOptionPane</p>
  
  <p>How can I do this?</p>
  
  <pre><code>import javax.swing.JOptionPane;
  
  public class OptionPane {
      public static void main(final String[] args) {
          int value = 0;
          boolean isPositive = false , isNumeric = true;
          do {
              try {
                  value = Integer.parseInt(JOptionPane.showInputDialog(null,
                      "Enter value?", null));
              } catch (NumberFormatException e) {
                  System.out.println("*** Please enter an integer ***");
                  isNumeric = false;
              }
  
               if(isNumeric) {
                  if(value &lt;= 0) {
                      System.out.println("value cannot be 0 or negative");
                  }
  
                  else {
                      System.out.println("value is positive");
                      isPositive = true;
                  }
              }
          }while(!isPositive);
      }
  }
  </code></pre>