On my system, I have a window and a controller, but for some reason, it is never throwing the error, as expected:
Method that performs validation:
private void validacao(){
if((form.txtNome.getText() != null) && (form.txtEnd.getText() != null) && (form.txtTel.getText() != null)){
eventosForm();
}else{
JOptionPane.showMessageDialog(null, "Todos os campos devem estar preenchidos !");
}
}
Method that takes field values:
private void eventosForm(){
form.btnCadastrar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Cliente cliente = new Cliente();
cliente.setNome(form.txtNome.getText());
cliente.setEndereco(form.txtEnd.getText());
cliente.setTelefone(form.txtTel.getText());
clienteDB.add(cliente);
form.setVisible(false);
}
});
}
As I said before, even though I leave all fields empty, it performs the registration, I believe it may be because it is a void method, but I'm not sure ...