Calling up graphical interface in java

Asked

Viewed 290 times

6

My doubt is simple, I believe. 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, is a query command by CPF where I want to return the customer 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);



            }
  • You call Cadastrogui another screen and want it to be filled with information from the previous screen?

  • I have the template Registration ready, so I want to make a query through the CPF in another interface, call the Registration when filling the CPF and press a jbutton procurar and receive the information already setadas in the register that will be called

  • When I put this Cadasgui d = new Cadastrogui(); d.setVisible(true); it is coming, but it is not filled. I want it to be filled with the information that is connected to the CPF that I will look for.

  • This information comes from the screen that calls Cadasgui or you already bring direct from the bank?

  • 2

    careful when using the word interface in this way, in java it has another meaning. How do you send the information to Cadastrogui? it is a Jframe?

  • What @Skywalker said is true. I suggest you edit the question title to "graphical interface" since we’re talking about GUI’s.

  • I am learning more and more from you because I am a beginner in kk programming. I bring from the bank @Diegofelipe.

  • It’s Jframe yes @Skywalker, the information filled in in Jtextfields.

  • send the information you want to display in Cadastrogui by a constructor. Build a constructor in Cadastrogui.

Show 4 more comments

1 answer

4

Create another constructor in Cadasgui 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);
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.