How to check if fields are empty before adding in arraylist? [duplicate]

0

I have a question: how could I check if the fields in my JTextFields are empty before adding in arraylist ?, how would validation be in this part of code?

                Endereco enderecoPJ=new Endereco();
                PessoaJuridica pessoaJuridica=new PessoaJuridica();


                pessoaJuridica.setNome(tfNome.getText());
                pessoaJuridica.setSobrenome(tfSobrenome.getText());
                pessoaJuridica.setCnpj((Long.valueOf(tfIndentificador.getText())));


                enderecoPJ.setBairro(tfBairro.getText());
                enderecoPJ.setCep(Long.valueOf(tfCep.getText()));
                enderecoPJ.setCidade((String)cbCidades.getSelectedItem());
                enderecoPJ.setNum(Integer.valueOf(tfNum.getText()));
                enderecoPJ.setRua(tfRua.getText());

                pessoaControler.pj.add(pessoaJuridica);

                JOptionPane.showMessageDialog(null, "Cadastrado com Sucesso !");
    
asked by anonymous 20.09.2017 / 02:18

1 answer

-1

You can create a method to check this.

In it you will pass as parameter your JTextFields and check whether it is empty or not.

Then you need to make an if for each JTextFields that you want to add to the array.

It is a very simple logic, if you have questions about how to do it, you can comment here that we try to help.

Good luck!

    
20.09.2017 / 02:23