title: I need to vailidate user input and have user reenter if invalid in java
body: <p>I have to validate my user input for an integer value and prompt the user to reenter if an invalid value is entered. Thus far I have put together this method below. i believe the logic is correct but I need to get the user to reenter input again after the error message.         </p>
  
  <pre><code>void validateItemquantity() {
      boolean error = true;
      while (error) {
          try{ 
              Integer.parseInt(itemQuantityinput.getText());
              error = false; 
          }
          catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(null, "Item quantity must be a positive number, please reenter");
              error = true; 
          }
      }
  }
  </code></pre>
  
  <p>Part of code from jframe method:</p>
  
  <pre><code>private void bnPurchaseActionPerformed(java.awt.event.ActionEvent evt) {                                           
  
          String itemCode; 
          int itemQuantity, itemPrice, itemCost, totalCost ;
  
          validateItemquantity();
          itemCode = itemCodeinput.getText();
          itemQuantity = Integer.parseInt(itemQuantityinput.getText());
          itemPrice = catalog.searchCatalog(itemCode);
          itemCost = payment.calculateItemcost(itemQuantity,itemPrice);
          totalCost = payment.calculateTotalcost(itemCost);
  </code></pre>