title: Converting JOptionPane input to integer
body: <p>I'm trying to write a simple program that will ask for the user to enter a number in-between 1 and 10, then display the number. Now I have gotten part to work where if the number is outside of the range it asks again, but I can't seem to get it to ask again if anything aside from a number is inputted, such as <code>%</code> or <code>hello</code>.</p>
  
  <p>The source code: (Cut out the top)</p>
  
  <pre><code>public static void main(String[] args){
  
      int number;                 //For holding the number
      String stringInput;         //For holding the string values until converted
  
  
      //------------------//
      //Introducing the user
  
      JOptionPane.showMessageDialog(null, "This is a program that will ask \n"
                                          + "you to enter a number in-between \n"
                                          + "1-10, if the number is not within \n"
                                          + "the parameters, the program will repeat.");
  
  
      //---------------------//
      //Get input from the user
  
      stringInput = JOptionPane.showInputDialog("Enter number.");
  
      number = Integer.parseInt(stringInput);
  
  
      //-----------------//
      //Checking the number
  
      while (number &gt; 10 || number &lt; 0){
  
          stringInput = JOptionPane.showInputDialog("That number is not within the \n"
                                                    + "allowed range! Enter another number.");
  
          number = Integer.parseInt(stringInput);
  
      }
  
  
      //-------------------//
      //Displaying the number
  
      JOptionPane.showMessageDialog(null, "The number you chose is "
                                          + number
                                          + ".");
  
  
      //-------------//
      //Closing it down
          System.exit(0);
  }
  </code></pre>
  
  <p>The main problem is the:</p>
  
  <pre><code>number = Integer.parseInt(stringInput);
  </code></pre>
  
  <p>I can't seem to convert the data values properly. I already thought of something like using an if statement to determine if the number is an integer, but I couldn't figure out how to check. I wish I could do:</p>
  
  <pre><code>if (number == Integer)
  </code></pre>
  
  <p>As you can see I am still extremely new to Java, any help is appreciated, thanks for taking the time to read.</p>