Bom o c´digo dos botões eu acabei excluindo pq não davam certo
mas as classes são essas
//ClientesControle.java
package Classes;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Formularios.ClientesGUI;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Casa
*/
public class ClientesControle {
public ClientesGUI cliGUI;
public ClientesControle() {
cliGUI = new ClientesGUI();
cliGUI.adicionarCliente(new IncluirCliente());
}
//classe interna
class IncluirCliente implements ActionListener {
public void actionPerformed(ActionEvent av) {
Object fonte = av.getSource();
if (fonte == cliGUI.btnSair)
cliGUI.dispose();
else if (fonte == cliGUI.btnLimpar)
cliGUI.limparCampos();
else if (fonte == cliGUI.btnExcluir) {
ClienteDB clienteDB = new ClienteDB();
clienteDB.excluirCliente(cliGUI.edtCodigo.getText());
cliGUI.limparCampos();
}
else if (fonte == cliGUI.btnIrPara) {
ClienteDB clienteDB = new ClienteDB();
Clientes cliente = clienteDB.irParaCliente();
if (cliente != null)
mostrarCliente(cliente);
}
else if (fonte == cliGUI.btnIncluir) {
ClienteDB clienteDB = new ClienteDB();
Clientes cliente = obterCliente();
clienteDB.incluirCliente(cliente);
cliGUI.limparCampos();
}
else if (fonte == cliGUI.btnAlterar) {
ClienteDB clienteDB = new ClienteDB();
Clientes cliente = obterCliente();
clienteDB.alterarCliente(cliente);
}
}
}
public Clientes obterCliente(){
Clientes cliente = new Clientes();
cliente.setNome(cliGUI.edtNome.getText());
cliente.setCodigo(Integer.parseInt(cliGUI.edtCodigo.getText()));
cliente.setSite(cliGUI.edtSite.getText());
cliente.setEndereco(cliGUI.edtEndereco.getText());
cliente.setNumero(Integer.parseInt(cliGUI.edtNumero.getText()));
cliente.setBairro(cliGUI.edtBairro.getText());
cliente.setCep(cliGUI.edtCep.getText());
cliente.setCidade(cliGUI.edtCidade.getText());
cliente.setEstado((String) cliGUI.comboEstado.getSelectedItem());
cliente.setContato(cliGUI.edtContato.getText());
cliente.setCargo(cliGUI.edtCargo.getText());
cliente.setTelefone(cliGUI.edtTelefone.getText());
cliente.setCelular(cliGUI.edtCelular.getText());
cliente.setObservacao(cliGUI.edtObservacao.getText());
return cliente;
}
public void mostrarCliente(Clientes cliente) {
cliGUI.edtNome.setText(cliente.getNome());
cliGUI.edtCodigo.setText(String.valueOf(cliente.getCodigo()));
cliGUI.edtSite.setText(cliente.getSite());
cliGUI.edtEndereco.setText(cliente.getEndereco());
cliGUI.edtNumero.setText(String.valueOf(cliente.getNumero()));
cliGUI.edtBairro.setText(cliente.getBairro());
cliGUI.edtCep.setText(cliente.getCep());
cliGUI.edtCidade.setText(cliente.getCidade());
cliGUI.comboEstado.setSelectedItem(cliente.getEstado());
cliGUI.edtContato.setText(cliente.getContato());
cliGUI.edtCargo.setText(cliente.getCargo());
cliGUI.edtTelefone.setText(cliente.getTelefone());
cliGUI.edtCelular.setText(cliente.getCelular());
cliGUI.edtObservacao.setText(cliente.getObservacao());
}
}
package Formularios;
import Classes.Clientes;
import java.awt.event.ActionListener;
import javax.swing.JInternalFrame;
import Classes.ClientesControle;
public class ClientesGUI extends JInternalFrame {
ClientesControle cliControl;
/** Creates new form ClientesGUI */
public ClientesGUI() {
initComponents();
//cliControl = new ClientesControle();
}
/** 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel6 = new javax.swing.JLabel();
edtBairro = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
edtCargo = new javax.swing.JTextField();
jLabel14 = new javax.swing.JLabel();
comboEstado = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
btnAlterar = new javax.swing.JButton();
edtNumero = new javax.swing.JTextField();
btnIrPara = new javax.swing.JButton();
jLabel11 = new javax.swing.JLabel();
edtCep = new javax.swing.JTextField();
edtCelular = new javax.swing.JTextField();
btnLimpar = new javax.swing.JButton();
btnIncluir = new javax.swing.JButton();
edtContato = new javax.swing.JTextField();
edtSite = new javax.swing.JTextField();
edtEndereco = new javax.swing.JTextField();
edtNome = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
btnSair = new javax.swing.JButton();
edtTelefone = new javax.swing.JTextField();
edtCodigo = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
edtObservacao = new javax.swing.JTextArea();
btnExcluir = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
edtCidade = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Cadastro de Clientes");
jLabel6.setText("Número");
jLabel7.setText("Bairro");
jLabel2.setText("Nome");
jLabel10.setText("Estado");
jLabel13.setText("Telefone");
jLabel14.setText("Celular");
comboEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\"\"", "RS", "SC", "PR", "SP", "RJ", "MG", "ES", "MS", "MT", "GO", "DF", "BA", "SE", "AL ", "PE", "PB", "RN", "CE", "PI ", "MA", "TO", "PA", "AP", "RR", "AM", "RO", "AC" }));
jLabel4.setText("Site");
jLabel12.setText("Cargo");
btnAlterar.setText("Alterar");
btnIrPara.setText("Ir Para");
jLabel11.setText("Contato");
btnLimpar.setText("Limpar Campos");
btnLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLimparActionPerformed(evt);
}
});
btnIncluir.setText("Incluir");
jLabel5.setText("Endereço");
jLabel9.setText("CEP");
btnSair.setText("Fechar Janela");
edtObservacao.setColumns(20);
edtObservacao.setRows(5);
jScrollPane1.setViewportView(edtObservacao);
btnExcluir.setText("Excluir");
jLabel3.setText("Código");
jLabel8.setText("Cidade");
jLabel15.setText("Observação");
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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addContainerGap(622, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(36, 36, 36)
.addComponent(edtSite, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(edtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(edtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(69, 69, 69))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addContainerGap(616, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(edtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel14)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(318, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(edtEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(comboEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edtContato))
.addGroup(layout.createSequentialGroup()
.addComponent(edtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel9)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(edtCep, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edtCidade, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(edtCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)))))
.addGap(69, 69, 69))
.addGroup(layout.createSequentialGroup()
.addComponent(btnIncluir)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnExcluir)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnAlterar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnIrPara)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnLimpar)
.addContainerGap(256, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnSair)
.addGap(83, 83, 83))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(edtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(edtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(edtSite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(edtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(edtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(edtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(edtCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8)
.addComponent(edtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(comboEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(edtContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(edtCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel13)
.addComponent(edtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14)
.addComponent(edtCelular, 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)
.addComponent(jLabel15)
.addComponent(jScrollPane1, 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.BASELINE)
.addComponent(btnIncluir)
.addComponent(btnExcluir)
.addComponent(btnAlterar)
.addComponent(btnIrPara)
.addComponent(btnLimpar))
.addGap(18, 18, 18)
.addComponent(btnSair)
.addContainerGap(68, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {
this.limparCampos();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClientesGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JButton btnAlterar;
public javax.swing.JButton btnExcluir;
public javax.swing.JButton btnIncluir;
public javax.swing.JButton btnIrPara;
public javax.swing.JButton btnLimpar;
public javax.swing.JButton btnSair;
public javax.swing.JComboBox comboEstado;
public javax.swing.JTextField edtBairro;
public javax.swing.JTextField edtCargo;
public javax.swing.JTextField edtCelular;
public javax.swing.JTextField edtCep;
public javax.swing.JTextField edtCidade;
public javax.swing.JTextField edtCodigo;
public javax.swing.JTextField edtContato;
public javax.swing.JTextField edtEndereco;
public javax.swing.JTextField edtNome;
public javax.swing.JTextField edtNumero;
public javax.swing.JTextArea edtObservacao;
public javax.swing.JTextField edtSite;
public javax.swing.JTextField edtTelefone;
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 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.JScrollPane jScrollPane1;
// End of variables declaration
public void limparCampos()
{
edtCodigo.setText("");
edtNome.setText("");
edtSite.setText("");
edtEndereco.setText("");
edtNumero.setText("");
edtBairro.setText("");
edtCep.setText("");
edtCidade.setText("");
comboEstado.setSelectedItem("");
edtContato.setText("");
edtCargo.setText("");
edtTelefone.setText("");
edtCelular.setText("");
edtObservacao.setText("");
}
public void adicionarCliente(ActionListener ouvinte) {
this.btnIncluir.addActionListener(ouvinte);
this.btnExcluir.addActionListener(ouvinte);
this.btnAlterar.addActionListener(ouvinte);
this.btnIrPara.addActionListener(ouvinte);
this.btnSair.addActionListener(ouvinte);
this.btnLimpar.addActionListener(ouvinte);
}
}
NOs botões eu estava tentando fazer uma referencia ao método AdicionarCliente
Falou 8)