Classe Para Cadastrar Clientes

Gente, preciso de uma ajuda.Tenho uma classe que tem um método, que por sua vez , recebe em parametros o numero de clientes para cadastrar.E Pra cada cliente será feito um cadastro.
Gostaria de saber como posso fazer isso
A classe que esta o método signClients não extende JFrame. Mas a CadastrarCliente é uma classe com interface.
Estou totalmente sem idéia.Preciso cadastrar o número de clientes que eu receber nessa classe.

[code]public void signClients(int qnt)
{
int numClientes[] = new int[qnt];
numClientes[0] = 1;

for(int i = 0; i < qnt ;i++)
{
CadastrarCliente c1 = new CadastrarCliente();
c1.setSize(1024,768);
c1.setVisible(true);
}
}[/code]

Ao invés de você instanciar todas as telas de cadastro no método, sugiro que você somente instancie uma nova tela quando tiver a garantia de que o cadastro anterior foi feito com sucesso. Afinal de contas, se o usuário simplesmente fechar uma janela, sem cadastrar, não pode contar como um cadastro.

Você tem algum método salvar nesta classe de cadastro? Ela insere num banco? Como funciona este cadastro?

Minha sugestão, sem conhecer muito seu problema, seria que, no método salvar da classe cadastro, após tudo ter ocorrido certo, você notifique esta classe que gerencia (a classe que contém o método signClients). Ao notificar a classe, ela fica responsável por incrementar o contador e abrir uma nova janela de cadastro, se necessário.

[quote=wagnerfrancisco]Ao invés de você instanciar todas as telas de cadastro no método, sugiro que você somente instancie uma nova tela quando tiver a garantia de que o cadastro anterior foi feito com sucesso. Afinal de contas, se o usuário simplesmente fechar uma janela, sem cadastrar, não pode contar como um cadastro.

Você tem algum método salvar nesta classe de cadastro? Ela insere num banco? Como funciona este cadastro?

Minha sugestão, sem conhecer muito seu problema, seria que, no método salvar da classe cadastro, após tudo ter ocorrido certo, você notifique esta classe que gerencia (a classe que contém o método signClients). Ao notificar a classe, ela fica responsável por incrementar o contador e abrir uma nova janela de cadastro, se necessário.[/quote]

Muito obrigado pela resposta.
Wagner,

È exatamente isso que quero fazer.
Essa classe de cadastro coloca tudo no banco de dados. E depois de clicar em submit. Ele deve abrir uma nova tela de cadastro. Como posso fazer isso de notificar?

A maneira “mais bonita” de se fazer isto é utilizar o padrão Observer. Dê uma procurada que irá encontrar vários exemplos de código.

Uma maneira simples, que vai deixar seu código mais acoplado, é na classe CadastroDeCliente, receber o objeto que está coordenando estas chamadas. O objeto que contém o método signClients. Seria algo assim:

public class CadastrarCliente {
   private GerenciadorDeCadastro gerenciador; //estou supondo que o nome da classe eh GerenciadorDeCadastro... possivelmente nao eh

   public CadastrarCliente(GerenciadorDeCadastro gerenciador) {
      super();
      this.gerenciador = gerenciador;
   }

   public void salvar() {
      //sua logica de salvar aqui
      gerenciador.clienteSalvo();
   }
}

E no seu gerenciador, quando instanciar o CadastrarCliente, vc passa uma referência usando this.

Enfim, vc percebeu que a classe CadastrarCliente vai ter uma depender da classe GerenciadorDeCadastro. Se isto for um problema pra vc, sugiro que dê uma olhada no padrão Observer, que mencionei anteriormente.

Abraço.

[code]/*

  • To change this template, choose Tools | Templates

  • and open the template in the editor.
    /
    package CadastrarCliente;
    import com.mysql.jdbc.Statement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.swing.JOptionPane;
    import neucomairport.
    ;
    /**

  • @author André
    */
    public class CadastrarCliente extends javax.swing.JFrame {

    private static Connection conn = null;
    protected static String ErrorLog,error;
    private static String estadoCivil,nome,CPFCNPJ,email,endereco,pontoReferencia,
    telefoneRes,telefoneCom,celular,sexo,nomePai,nomeMae,dataNasc,CEP,
    bairro,cidade,pais,estado;
    //Tipo = pessoa Física ou Jurídica;

    public CadastrarCliente() {
    initComponents();
    }

    /**

    • This method is called from within the constructor to initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is always

    • regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      jTextField_NomeCliente = new javax.swing.JTextField();
      jTextField_NomePai = new javax.swing.JTextField();
      jTextField_NomeMae = new javax.swing.JTextField();
      jTextField_CPFCNPJ = new javax.swing.JTextField();
      jTextField_Endereco = new javax.swing.JTextField();
      jTextField_CEP = new javax.swing.JTextField();
      jTextField_Cidade = new javax.swing.JTextField();
      jTextField_Estado = new javax.swing.JTextField();
      jTextField_pais = new javax.swing.JTextField();
      jScrollPane1 = new javax.swing.JScrollPane();
      jTextArea1 = new javax.swing.JTextArea();
      jLabel1 = new javax.swing.JLabel();
      jLabel2 = new javax.swing.JLabel();
      jTextField_TelRes = new javax.swing.JTextField();
      jTextField_TelComercial = new javax.swing.JTextField();
      jTextField_Celular = new javax.swing.JTextField();
      jButton1 = new javax.swing.JButton();
      jButton_SignUpCadastrar = new javax.swing.JButton();
      jTextField_EstadoCivil = new javax.swing.JTextField();
      jLabel3 = new javax.swing.JLabel();
      jLabel4 = new javax.swing.JLabel();
      jLabel5 = new javax.swing.JLabel();
      jLabel6 = new javax.swing.JLabel();
      jLabel7 = new javax.swing.JLabel();
      jLabel8 = new javax.swing.JLabel();
      jLabel9 = new javax.swing.JLabel();
      jLabel10 = new javax.swing.JLabel();
      jLabel11 = new javax.swing.JLabel();
      jLabel12 = new javax.swing.JLabel();
      jLabel13 = new javax.swing.JLabel();
      jLabel14 = new javax.swing.JLabel();
      jTextField_DataNasc = new javax.swing.JTextField();
      jLabel15 = new javax.swing.JLabel();
      jTextField_Email = new javax.swing.JTextField();
      jLabel16 = new javax.swing.JLabel();
      jTextField_Sexo = new javax.swing.JTextField();
      jLabel17 = new javax.swing.JLabel();
      jMenuBar1 = new javax.swing.JMenuBar();
      jMenu1 = new javax.swing.JMenu();
      jMenu2 = new javax.swing.JMenu();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jTextField_NomeCliente.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField_NomeClienteActionPerformed(evt);
      }
      });
      jTextField_NomeCliente.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_NomeClienteFocusGained(evt);
      }
      });

      jTextField_NomePai.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_NomePaiFocusGained(evt);
      }
      });

      jTextField_NomeMae.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_NomeMaeFocusGained(evt);
      }
      });

      jTextField_CPFCNPJ.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField_CPFCNPJActionPerformed(evt);
      }
      });
      jTextField_CPFCNPJ.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_CPFCNPJFocusGained(evt);
      }
      });

      jTextField_Endereco.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField_EnderecoActionPerformed(evt);
      }
      });
      jTextField_Endereco.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_EnderecoFocusGained(evt);
      }
      });

      jTextField_CEP.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_CEPFocusGained(evt);
      }
      });

      jTextField_Cidade.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_CidadeFocusGained(evt);
      }
      });

      jTextField_Estado.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField_EstadoActionPerformed(evt);
      }
      });
      jTextField_Estado.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_EstadoFocusGained(evt);
      }
      });

      jTextField_pais.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_paisFocusGained(evt);
      }
      });

      jTextArea1.setColumns(20);
      jTextArea1.setRows(5);
      jTextArea1.setText(“Ref.Point From \nResidence\n”);
      jTextArea1.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextArea1FocusGained(evt);
      }
      });
      jScrollPane1.setViewportView(jTextArea1);

      jLabel1.setFont(new java.awt.Font(“Tunga”, 0, 24)); // NOI18N
      jLabel1.setText(“Address”);

      jLabel2.setFont(new java.awt.Font(“Tahoma”, 0, 18)); // NOI18N
      jLabel2.setText(“Sign up Client”);

      jTextField_TelRes.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_TelResFocusGained(evt);
      }
      });

      jTextField_TelComercial.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_TelComercialFocusGained(evt);
      }
      });

      jTextField_Celular.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_CelularFocusGained(evt);
      }
      });

      jButton1.setText(“Localizar”);

      jButton_SignUpCadastrar.setText(“Cadastrar”);
      jButton_SignUpCadastrar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jButton_SignUpCadastrarActionPerformed(evt);
      }
      });

      jTextField_EstadoCivil.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_EstadoCivilFocusGained(evt);
      }
      });

      jLabel3.setText(“Complete Name”);

      jLabel4.setText(“Father’s Name”);

      jLabel5.setText(“Mother’s Name”);

      jLabel6.setText("SSN / IDCard ");

      jLabel7.setText(“Residential / Commercial Phone Number”);

      jLabel8.setText(“CellPhone”);

      jLabel9.setText(“Civil State - Single, Married”);

      jLabel10.setText(“Adress:”);

      jLabel11.setText(“ZipCode:”);

      jLabel12.setText(“City:”);

      jLabel13.setText(“State”);

      jLabel14.setText(“Country”);

      jTextField_DataNasc.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
      jTextField_DataNascFocusGained(evt);
      }
      });

      jLabel15.setText(“BirthDay”);

      jLabel16.setText(“Email”);

      jLabel17.setText("Sex ");

      jMenu1.setText(“File”);
      jMenuBar1.add(jMenu1);

      jMenu2.setText(“Edit”);
      jMenuBar1.add(jMenu2);

      setJMenuBar(jMenuBar1);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(jTextField_NomeCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
      .addComponent(jTextField_NomePai)
      .addComponent(jTextField_NomeMae)
      .addComponent(jTextField_CPFCNPJ))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
      .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING))
      .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addGap(223, 223, 223))
      .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(18, 18, 18)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jButton_SignUpCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jTextField_Estado, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jLabel13))
      .addGroup(layout.createSequentialGroup()
      .addComponent(jTextField_pais, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jLabel14))))
      .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jTextField_Endereco)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jTextField_CEP, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel12)
      .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(jButton1))
      .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jTextField_Celular, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
      .addComponent(jTextField_Sexo, javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jTextField_Email)
      .addComponent(jTextField_DataNasc, javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jTextField_EstadoCivil, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel9)
      .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGroup(layout.createSequentialGroup()
      .addComponent(jTextField_TelRes, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jTextField_TelComercial, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(18, 18, 18)
      .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGap(25, 25, Short.MAX_VALUE))))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jLabel2)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_NomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel3))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_NomePai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel4))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_NomeMae, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel5))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_CPFCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel6))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_TelRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jTextField_TelComercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel7))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_Celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel8))
      .addGap(18, 18, 18)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_EstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel9))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_DataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel15))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_Email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel16))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_Sexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel17))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(4, 4, 4)
      .addComponent(jLabel10)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jTextField_Endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(jLabel12)
      .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jTextField_CEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jButton1))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(23, 23, 23))
      .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_Estado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel13))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField_pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel14))
      .addGap(18, 18, 18)
      .addComponent(jButton_SignUpCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addContainerGap())))
      );

      pack();
      }//

    private void jTextField_EnderecoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_EstadoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_CPFCNPJActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void jButton_SignUpCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
    String driverName = “com.mysql.jdbc.Driver”;
    String serverName = //caminho do servidor do BD
    String mydatabase =
    String url = “jdbc:mysql://” + serverName + “/” + mydatabase;
    String username =
    String password =
    String command = “null”;

     try {
          CPFCNPJ = jTextField_CPFCNPJ.getText();
          nome = jTextField_NomeCliente.getText();
          dataNasc = jTextField_DataNasc.getText();
          nomePai = jTextField_NomePai.getText();
          nomeMae = jTextField_NomeMae.getText();
          estadoCivil = jTextField_EstadoCivil.getText();
          telefoneRes = jTextField_TelRes.getText();
          telefoneCom = jTextField_TelComercial.getText();
          celular = jTextField_Celular.getText();
          CEP = jTextField_CEP.getText();
          endereco = jTextField_Endereco.getText();        
          pais = jTextField_pais.getText();
          pontoReferencia = jTextArea1.getText();
          email = jTextField_Email.getText();
          sexo = jTextField_Sexo.getText();
         
         command = "insert into airlines.cliente (CPFCNPJ,Nome,DataNasc,NomePai,NomeMae,EstadoCivil,TelefoneRes,TelefoneCom,Celular,CEP,Endereco,Bairro,Cidade,Estado,Pais,PontoReferencia,Email,Sexo)"
                 + " " + "values('"+CPFCNPJ+"','"+nome+"','"+dataNasc+"','"+nomePai+"','"+nomeMae+"','"+estadoCivil+"','"+telefoneRes+"','"+telefoneCom+"','"+celular+"','"+CEP+"','"+endereco+"','"+bairro+"','"+cidade+"','"+estado+"','"+pais+"','"+pontoReferencia+"','"+email+"','"+sexo+"');";
                 
         conn = DriverManager.getConnection(url, username, password);
         Statement stm = (Statement) conn.createStatement();
         stm.execute(command);
         
         
         
     }catch(SQLException ex)
     {
         error = "ex";
         ErrorLog = ex.getMessage();
         //NoteFileGen4.saveErrorLog(ErrorLog);
         ErrorLog = null;
         System.out.println("" + ex.getMessage());
     }
     
     if (error != null)
     {
         JOptionPane.showMessageDialog(null,"Error when Signing Client");
     }
     
     
     error = null;
    

    }

    private void jTextField_NomeClienteFocusGained(java.awt.event.FocusEvent evt) {

    }

    private void jTextField_NomePaiFocusGained(java.awt.event.FocusEvent evt) {

    }

    private void jTextField_NomeMaeFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_CPFCNPJFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_TelResFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_TelComercialFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_CelularFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_EstadoCivilFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_DataNascFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_EnderecoFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_CEPFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_CidadeFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_EstadoFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_paisFocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextArea1FocusGained(java.awt.event.FocusEvent evt) {
    // TODO add your handling code here:
    }

    private void jTextField_NomeClienteActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    /**

    • @param args the command line arguments
      /
      public static void main(String args[]) {
      /
      Set the Nimbus look and feel /
      //
      /
      If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

      • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if (“Nimbus”.equals(info.getName())) {
        javax.swing.UIManager.setLookAndFeel(info.getClassName());
        break;
        }
        }
        } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CadastrarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(CadastrarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(CadastrarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(CadastrarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new CadastrarCliente().setVisible(true);
      }
      });
      }
      // Variables declaration - do not modify
      private javax.swing.JButton jButton1;
      private javax.swing.JButton jButton_SignUpCadastrar;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel10;
      private javax.swing.JLabel jLabel11;
      private javax.swing.JLabel jLabel12;
      private javax.swing.JLabel jLabel13;
      private javax.swing.JLabel jLabel14;
      private javax.swing.JLabel jLabel15;
      private javax.swing.JLabel jLabel16;
      private javax.swing.JLabel jLabel17;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel3;
      private javax.swing.JLabel jLabel4;
      private javax.swing.JLabel jLabel5;
      private javax.swing.JLabel jLabel6;
      private javax.swing.JLabel jLabel7;
      private javax.swing.JLabel jLabel8;
      private javax.swing.JLabel jLabel9;
      private javax.swing.JMenu jMenu1;
      private javax.swing.JMenu jMenu2;
      private javax.swing.JMenuBar jMenuBar1;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JTextArea jTextArea1;
      private javax.swing.JTextField jTextField_CEP;
      private javax.swing.JTextField jTextField_CPFCNPJ;
      private javax.swing.JTextField jTextField_Celular;
      private javax.swing.JTextField jTextField_Cidade;
      private javax.swing.JTextField jTextField_DataNasc;
      private javax.swing.JTextField jTextField_Email;
      private javax.swing.JTextField jTextField_Endereco;
      private javax.swing.JTextField jTextField_Estado;
      private javax.swing.JTextField jTextField_EstadoCivil;
      private javax.swing.JTextField jTextField_NomeCliente;
      private javax.swing.JTextField jTextField_NomeMae;
      private javax.swing.JTextField jTextField_NomePai;
      private javax.swing.JTextField jTextField_Sexo;
      private javax.swing.JTextField jTextField_TelComercial;
      private javax.swing.JTextField jTextField_TelRes;
      private javax.swing.JTextField jTextField_pais;
      // End of variables declaration
      }
      [/code]

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */

package neucomairport;

import CadastrarCliente.CadastrarCliente;
import Passagem.DisponiveisVoos;
import java.awt.Image;

/**
*

  • @author André Vinícius Lopes
    */
    public class AuxClass {
    protected String aux;
    protected int idVoo,quantidadeTotalPassageiros,quantidadeCriancas,quantidadeAdultos,quantidadeBebes,valorTotalPassagens;
    protected boolean auxC;

public static void main(String args[])
{
System.out.println(“Aux Class Initiated;”);
}

public AuxClass()
{
idVoo = -1;
quantidadeTotalPassageiros = -1;
quantidadeCriancas = -1;
quantidadeAdultos = -1;
quantidadeBebes = -1;
valorTotalPassagens = -1;
aux = null;
auxC = false;

}

public void setALL(int valorTotal, int idVooSelecionado, int qntPassageiros, int qntAdultos, int qntCriancas, int qntBebes) {

   this.valorTotalPassagens = valorTotal;
   this.idVoo = idVooSelecionado;
   this.quantidadeTotalPassageiros = qntPassageiros; // Tem que ser passado para a próxima classe;
   this.quantidadeAdultos = qntAdultos; 
   this.quantidadeCriancas = qntCriancas;
   this.quantidadeBebes = qntBebes;
   System.out.println("Valor Total + id Voo Selecionado :" + valorTotal + "\n$ID" + idVooSelecionado );
   signClients(qntPassageiros);
 }

public void signClients(int qnt)
{
int numClientes[] = new int[qnt];
numClientes[0] = 1;

for(int i = 0; i < qnt ;i++)
{
CadastrarCliente c1 = new CadastrarCliente();
c1.setSize(1024,768);
c1.setVisible(true);

}

}

public String getAux() {
return aux;
}

public void setAux(String aux) {
    this.aux = aux;
}

public int getIdVoo() {
    return idVoo;
}

public void setIdVoo(int idVoo) {
    this.idVoo = idVoo;
}

public int getQuantidadeTotalPassageiros() {
    return quantidadeTotalPassageiros;
}

public void setQuantidadeTotalPassageiros(int quantidadeTotalPassageiros) {
    this.quantidadeTotalPassageiros = quantidadeTotalPassageiros;
}

public int getQuantidadeCriancas() {
    return quantidadeCriancas;
}

public void setQuantidadeCriancas(int quantidadeCriancas) {
    this.quantidadeCriancas = quantidadeCriancas;
}

public int getQuantidadeAdultos() {
    return quantidadeAdultos;
}

public void setQuantidadeAdultos(int quantidadeAdultos) {
    this.quantidadeAdultos = quantidadeAdultos;
}

public int getQuantidadeBebes() {
    return quantidadeBebes;
}

public void setQuantidadeBebes(int quantidadeBebes) {
    this.quantidadeBebes = quantidadeBebes;
}

public int getValorTotalPassagens() {
    return valorTotalPassagens;
}

public void setValorTotalPassagens(int valorTotalPassagens) {
    this.valorTotalPassagens = valorTotalPassagens;
}

public boolean isAuxC() {
    return auxC;
}

public void setAuxC(boolean auxC) {
    this.auxC = auxC;
}

}
[/code]

[code]

public class CadastrarCliente {
private GerenciadorDeCadastro gerenciador; //estou supondo que o nome da classe eh GerenciadorDeCadastro… possivelmente nao eh

public CadastrarCliente(GerenciadorDeCadastro gerenciador) {
super();
this.gerenciador = gerenciador;
}

public void salvar() {
//sua logica de salvar aqui
gerenciador.clienteSalvo();
}
} [/code]

Não entendi isso aqui…

Tá meio estranha está sua AuxClass, me parece que tudo está concentrado ali. Mas por ora é melhor fazer funcionar do jeito que está. No exemplo que lhe dei, a classe GerenciadorDeCadastro seria a sua AuxClass. Algo assim:

public class CadastrarCliente extends javax.swing.JFrame {  
      
    private AuxClass auxiliar; //mantenha uma referencia para auxiliar 
    private static Connection conn = null;  
    protected static String ErrorLog,error;  
    private static  String estadoCivil,nome,CPFCNPJ,email,endereco,pontoReferencia,  
            telefoneRes,telefoneCom,celular,sexo,nomePai,nomeMae,dataNasc,CEP,  
            bairro,cidade,pais,estado;  
    //Tipo = pessoa Física ou Jurídica;  
              
              
      
    public CadastrarCliente(AuxClass auxiliar) {   //receba a referencia no construtor
        super(); //chame o construtor de jframe
        this.auxiliar = auxiliar; // guarde o objeto auxiliar
        initComponents();  
    }  

    //...

   private void jButton_SignUpCadastrarActionPerformed(java.awt.event.ActionEvent evt) {                                                          
        String driverName = "com.mysql.jdbc.Driver";  
        String serverName;
        String mydatabase;  
        String url = "jdbc:mysql://" + serverName + "/" + mydatabase;  
        String username;  
        String password;  
        String command = "null";  
          
          
        try {  
             CPFCNPJ = jTextField_CPFCNPJ.getText();  
             nome = jTextField_NomeCliente.getText();  
             dataNasc = jTextField_DataNasc.getText();  
             nomePai = jTextField_NomePai.getText();  
             nomeMae = jTextField_NomeMae.getText();  
             estadoCivil = jTextField_EstadoCivil.getText();  
             telefoneRes = jTextField_TelRes.getText();  
             telefoneCom = jTextField_TelComercial.getText();  
             celular = jTextField_Celular.getText();  
             CEP = jTextField_CEP.getText();  
             endereco = jTextField_Endereco.getText();          
             pais = jTextField_pais.getText();  
             pontoReferencia = jTextArea1.getText();  
             email = jTextField_Email.getText();  
             sexo = jTextField_Sexo.getText();  
              
            command = "insert into airlines.cliente (CPFCNPJ,Nome,DataNasc,NomePai,NomeMae,EstadoCivil,TelefoneRes,TelefoneCom,Celular,CEP,Endereco,Bairro,Cidade,Estado,Pais,PontoReferencia,Email,Sexo)"  
                    + " " + "values('"+CPFCNPJ+"','"+nome+"','"+dataNasc+"','"+nomePai+"','"+nomeMae+"','"+estadoCivil+"','"+telefoneRes+"','"+telefoneCom+"','"+celular+"','"+CEP+"','"+endereco+"','"+bairro+"','"+cidade+"','"+estado+"','"+pais+"','"+pontoReferencia+"','"+email+"','"+sexo+"');";  
                      
            conn = DriverManager.getConnection(url, username, password);  
            Statement stm = (Statement) conn.createStatement();  
            stm.execute(command);  
              
            //AQUI voce sabe que tudo ocorreu bem, pode notificar a classe auxiliar:
            auxiliar.clienteSalvo();   
              
        }catch(SQLException ex)  
        {  
            error = "ex";  
            ErrorLog = ex.getMessage();  
            //NoteFileGen4.saveErrorLog(ErrorLog);  
            ErrorLog = null;  
            System.out.println("" + ex.getMessage());  
        }  
          
        if (error != null)  
        {  
            JOptionPane.showMessageDialog(null,"Error when Signing Client");  
        }  
          
          
        error = null;  
    }     

    //... codigo restante

Me parece que é isso. O que estamos fazendo aqui é simplesmente comunicar a classe AuxClass com a classe CadastrarCliente.

Tenho que fazer alguma mudança na outra classe?

E Tá meio estranha está sua AuxClass, me parece que tudo está concentrado ali
Como assim ?

E deixa eu te pedir, lols, meus dados do banco de dados estao na sua quote, tem como editar plx ?

Removidos os dados do banco. :smiley:

Tem que alterar sim. Ao invés de você instanciar 10 vezes a classe logo de início, vc vai instanciar um novo cadastro somente ao ter certeza que ele foi persistido.

Teria que criar o método clienteSalvo tb…

To meio sem tempo agora, mas qquer coisa depois eu posto mais detalhado!

ok ok. Só não entendi mesmo esse método cliente salvo.

Mas valeu!!!

O seu método signClients ficaria um pouco diferente.


//repare que sao atributos pertencentes a instancia
private int quantidadeParaCadastrar;
private int quantidadeDeCadastrosRealizados;

public void signClients(int qnt) {
   this.quantidadeParaCadastrar = qnt;
   this.quantidadeDeCadastrosRealizados = 0;
   cadastrarCliente();
}

public void cadastrarCliente() {
   if (this.quantidadeDeCadastrosRealizados < this.quantidadeParaCadastrar) {
      CadastrarCliente c1 = new CadastrarCliente();
      c1.setSize(1024,768);
      c1.setVisible(true);
   }
}

public void clienteSalvo() {
   this.quantidadeDeCadastrosRealizados++;
   cadastrarCliente(); //ao salvar tenta cadastrar novamente
}

Essa é uma ideia. Não sei que tipo de controle você planeja nesta aplicação, mas se os dados serão gravados num banco de dados e o usuário fechar a app e abrir novamente, você não tem garantia que 10 cadastros serão realizados.