How to make Jframe with Jmenubar by calling another Jframe?

Asked

Viewed 200 times

0

Hello, I have a main class that is working but when you click on the menu Register and then client it does not call the other screen Jframe Register clienteui.

Here is the snippet that was to call the other Jframe that is implemented in another class..

//criando o MenuItem cliente para executar o cadastro de clientes
    JMenuItem menuItemCadastro = new JMenuItem("Cadastro");
    menuItemCadastro.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e){
            new CadastroClienteUI();
        }
    });

here is the Customer Registration class

public class CadastroClienteUI {

public CadastroClienteUI(){

    final JFrame frameCadastroCliente = new JFrame("Cadastro de Cliente");
    frameCadastroCliente.setSize(400,240);
    frameCadastroCliente.setVisible(true);
    frameCadastroCliente.setLocationRelativeTo(null);

    JPanel panel = new JPanel();

    JLabel rotuloNome = new JLabel();
    rotuloNome.setText("Nome: ");
    panel.add(rotuloNome);

    final JTextField textFieldNome = new JTextField(30);
    panel.add(textFieldNome);

    JLabel rotuloTelefone = new JLabel();
    rotuloTelefone.setText("Telefone: ");
    panel.add(rotuloTelefone);

    final JTextField textFieldTelefone = new JTextField(30);
    panel.add(textFieldTelefone);

    JLabel rotuloRG = new JLabel();
    rotuloRG.setText("RG: ");
    panel.add(rotuloRG);

    final JTextField textFieldRG = new JTextField(30);
    panel.add(textFieldRG);

    JLabel rotuloCPF = new JLabel();
    rotuloCPF.setText("CPF: ");
    panel.add(rotuloCPF);

    final JTextField textFieldCPF = new JTextField(30);
    panel.add(textFieldCPF);

    JLabel rotuloEndereco = new JLabel();
    rotuloEndereco.setText("Endereço: ");
    panel.add(rotuloEndereco);

    final JTextField textFieldEndereco = new JTextField(30);
    panel.add(textFieldEndereco);

    JButton buttonSalvar = new JButton ("Salvar");
    buttonSalvar.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e){

            //InsereCliente insereCliente = new InsereCliente();
            JDBCClienteDAO insereCliente = new JDBCClienteDAO();

            Cliente cliente = new Cliente();
            cliente.setNome(textFieldNome.getText());
            cliente.setTelefone(textFieldTelefone.getText());
            cliente.setRG(textFieldRG.getText());
            cliente.setCPF(textFieldCPF.getText());
            cliente.setEndereco(textFieldEndereco.getText());

            insereCliente.gravaCliente(cliente);
        }
    });

    panel.add(buttonSalvar);

    JButton buttonCancelar = new JButton("Cancelar");
    buttonCancelar.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e){
        frameCadastroCliente.dispose();
        }
    });

    panel.add(buttonCancelar);

    frameCadastroCliente.setContentPane(panel);
    frameCadastroCliente.setVisible(true);
}

}

  • 1

    Simply put, there was no missing new Customer Registration ui(). setVisible(true);?

  • Do not accept, you have to create the setVisible method();

  • Add the code of the Customer Registration class to the question.

  • added the code of the Customer Registration class

  • Apart from the classes you have customised, here it worked normally.

No answers

Browser other questions tagged

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