Call graphical interface in java

6

My doubt is simple, I think. I need to call this interface CadastroGUI d = new CadastroGUI() ; which I already have ready, but I want the fields already appear filled, after all, it is a query command by CPF where I want to return the client information.

The Code

public void actionPerformed(ActionEvent arg0) {

                String cpf = txtCPF.getText();

                DaoCadastro c = new DaoCadastro();
                ArrayList <Cadastro> co = new ArrayList <Cadastro>();

                CadastroGUI d = new CadastroGUI();
                d.setVisible(true);

                co = c.listaAlterar(cpf);
                int a=0;

                for (a=0; a<co.size();a++)

                {
                    txtNome.setText (co.get(a).Nome);
                    txtCPF.setText (co.get(a).CPF);
                    txtEndereco.setText(co.get(a).Endereco);
                    txtSexo.setText(co.get(a).Sexo);
                    txtDataNasc.setText (co.get(a).Datanasc);



            }
    
asked by anonymous 01.12.2015 / 02:00

1 answer

4

Create another constructor in CadastroGUI with parameter for your arraylist:

    CadastroGUI(ArrayList<Cadastro> co)
    {
        CadastroGUI();
        //aqui você faz o preenchimento dos campos.
        int a=0;
        for (a=0; a < co.size(); a++)
        {
            txtNome.setText (co.get(a).Nome);
            txtCPF.setText (co.get(a).CPF);
            txtEndereco.setText(co.get(a).Endereco);
            txtSexo.setText(co.get(a).Sexo);
            txtDataNasc.setText (co.get(a).Datanasc);
        }
    }

And in your event you simply call it by passing the arraylist by parameter:

    public void actionPerformed(ActionEvent arg0) 
    {
        String cpf = txtCPF.getText();
        DaoCadastro c = new DaoCadastro();
        ArrayList <Cadastro> co = new ArrayList <Cadastro>();
        co = c.listaAlterar(cpf);
        CadastroGUI d = new CadastroGUI(co);
        d.setVisible(true);
    }
    
01.12.2015 / 03:03