I need help solving this please: I have TWO methods i want to execute, but i only want the both of them to be executed if any of the methods doesn't return an error! i have tried doing this:
//addButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ev){ boolean valid = true; String fnField = fnameField.getText(); String mnField = mnameField.getText(); String lnField = lnameField.getText(); String user = usnField.getText(); String sx = group.getSelection().getActionCommand(); // @SuppressWarnings("deprecation") String pwd = pwdField.getText(); // String img = imagePath.getText().trim(); Insert ins = new Insert(); int numField = 0; // employee emp = new employee(); String errCheck = emp.err(""); // if(fnField.equals(errCheck)){ valid = false; } if(mnField.equals(errCheck)){ valid = false; } if(lnField.equals(errCheck)){ valid = false; } if(user.equals(errCheck)){ valid = false; } if(pwd.equals(errCheck)){ valid = false; } if(isNum(numField) <= 0){ valid = false; JOptionPane.showMessageDialog(null, "The Id field must be a" + " number greater than 0!"); } if(img.equals(errCheck)){ valid = false; JOptionPane.showMessageDialog(null, "Please Choose an image!"); } if(valid){ ** emp.addEmployee(isNum(numField), user, pwd, fnField, mnField, lnField, sx); ** ins.ImageInsert(isNum(numField), (new File(img))); } } });
errCheck() is a method i created to check for errors in my forms! But i noticed that
** ins.ImageInsert(isNum(numField), (new File(img))); is executed even if there's an error with this: ** emp.addEmployee(isNum(numField), user, pwd, fnField, mnField, lnField, sx);
//
What can i do to prevent any of them executing if there's an error generated by at least one of them?