Java NetBeans中组合框的验证

时间:2019-04-11 11:07:31

标签: java netbeans

当前,我正在对表单进行im编码,该表单将居民分配给公寓系统的特定单元。因此,现在,我试图找出一种验证方法,例如,如果用户从要分配的组合框中选择特定单位编号,然后单击“提交”,则用户选择的列将消失或被禁用。在这个问题上,我需要一些帮助。我是否可以使用一种代码方法为无组合框创建验证?

combo box for assigning unit

  String fullname = fnameTxt.getText(); // check back your declaration for combobox 
    String block = (String) blockCbo.getSelectedItem();
    String floor = (String) floorCbo.getSelectedItem();
    String unit = (String) unitCbo.getSelectedItem();
    boolean isFound = false;

     if  ("".equals(fullname)) // check back your validation for this 
  {
        JOptionPane.showMessageDialog(null,"Resident's Full Name Is Mandatory.");
    }
      else  if (blockCbo.equals("NONE"))
  {
        JOptionPane.showMessageDialog(null,"Please Select A Block.");
    } 
      else  if (floorCbo.equals("NONE"))
  {
        JOptionPane.showMessageDialog(null,"Please Select A Floor Number.");
    } 
      else  if (unitCbo.equals("NONE"))
  {
        JOptionPane.showMessageDialog(null,"Please Select A Unit Number.");
    } 

     else {
        File file = new File("ResidentUnitDetails.txt");
        residentunit res = new residentunit(fullname, block, floor, unit);

        try (PrintWriter pw = new PrintWriter(new FileWriter(file, true))) {
            pw.println(res.toString());
            JOptionPane.showMessageDialog(this, "Resident Information Has Been Stored Successfully.");
             // enter validation for removing/disabling user selected combobox field
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

}                                         

0 个答案:

没有答案