mercredi 13 janvier 2021

how to check if the text fields are empty and print an appropriate message?

I just started doing java and i am stuck on the part where i have to check if the values in the text fields are empty or not and print an appropriate message but i am stuck on the part where i have to check my integer variable. what should i do?

String shoeName, brand, category,soldBy, size;

private void addshoetxtActionPerformed(java.awt.event.ActionEvent evt) {                                           
  try{
      int shoeId = Integer.parseInt(shoeidtxt.getText());
      shoeName = shoenametxt.getText();
      int price = Integer.parseInt(pricetxt.getText());
      brand = brandtxt.getText();
      category= "";
      size = "";
      soldBy = soldbytxt.getText();
      //shoe category
      category =  categorytxt.getSelectedItem().toString();
      //radio button for shoe size
      if(smalltxt.isSelected()){
          size = smalltxt.getText();
      } else if(mediumtxt.isSelected()){
          size = mediumtxt.getText();
      }else{
          size = largetxt.getText();
      }
      int rowCount = jTable1.getRowCount();
      String check = "";
      boolean flag = false;
      //if there is value in the table
      if(rowCount!=0){
          for(int i=0; i<rowCount-1; i++){
              check = jTable1.getValueAt(i,0).toString();
              if(check.equals(shoeId)){
                  System.out.println("Shoes Id already exists.");
                  flag = true;
                  break;
              }
          }
          //to check if the text fields are empty or not
          if(shoeId == 0)
      }
  }

}

Aucun commentaire:

Enregistrer un commentaire