Neste form efetuo uma pesquisa e consigo encontrar e mostrar nos campos, consigo efetuar edições e inclusões.
O Problema está nas exclusões o sistema da erro e acho que é na pasrte que ele faz esta busca.
Veja o trecho que eu falo e todo código fonte do form.
Obs.: O erro so ocorre se eu utilizar este trecho.
/*Trecho
*private void formWindowActivated(java.awt.event.WindowEvent evt) {
-
// TODO add your handling code here: -
if(!strSQL.isEmpty()){
-
try {
-
String sql = "SELECT * FROM ANALISTAS WHERE LOGIN ='" + strSQL + "'";
-
TabelaClientes.executeSQL(sql);
-
TabelaClientes.resultset.first();
-
mostradados();
-
sql = "SELECT * FROM ANALISTAS";
-
TabelaClientes.executeSQL(sql);
-
TabelaClientes.resultset.first();
-
} catch (SQLException erro) {
-
JOptionPane.showMessageDialog(null, "Nao foi possivel localizar Cliente");
-
//txtPesquisar.requestFocus(); -
mostradados();
-
} -
} - }
*/
//ABAIXO SEGUE OS FONTES DO FORM COMPLETO
/*
- Clientes.java
- Created on 18 de Dezembro de 2007, 12:11
*/
package Cadastros;
/**
*
-
@author Administrador
*/
import java.awt.AWTKeyStroke;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import utilitarios.conexao;
public class Analistas extends javax.swing.JFrame {
public static String strSQL="";
int navega = 0; //Identificar bot?o clicado
conexao TabelaClientes;
int situacaoEdicao = 0;/* Verifica a situacao de Edicao de registro
0. Navega??o ==> btSalvar desativado
1. Novo Registro ==> btSalvar Ativado e string (no evento click de btSalvat)
sqlNovo=“INSERT INTO…”
2. Editar Registro ==> btSalvar Ativado e string (no evento click de btSalvat)
sqlNovo="UPDATE …*/
/** Creates new form Clientes */
public Analistas() {
initComponents();
// Colocando enter para pular de campo
// HashSet conj = new HashSet(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
// conj.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
// this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, conj);
// Colocando enter para pular de campo
HashSet conj = new HashSet(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
conj.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, conj);
// txtPesquisar.addKeyListener(new KeyAdapter() {
//
// public void keyReleased(KeyEvent e) {
// String a = txtPesquisar.getText();
// if (a.length() >= 2000)//Transfere o foco com 10 caracteres.
// {
// txtPesquisar.transferFocus();
// }
// a = a.toUpperCase();//transforma tudo em maiuscula
// txtPesquisar.setText(a); //devolve para o jtextField
// }
// });
//
TabelaClientes = new conexao();
TabelaClientes.conecta();
TabelaClientes.executeSQL(“SELECT * FROM ANALISTAS”);
try {
TabelaClientes.resultset.first();
{
mostradados();
}
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null, “Não foram encontrados nenhum dos dados!” + erro);
}
exibeBotoes();
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtCodigo = new java.awt.TextField();
txtNome = new java.awt.TextField();
jLabel4 = new javax.swing.JLabel();
txtLogin = new java.awt.TextField();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtSenha = new java.awt.TextField();
btNovo = new javax.swing.JButton();
btPrimeiro = new javax.swing.JButton();
btAnterior = new javax.swing.JButton();
btEditar = new javax.swing.JButton();
btSalvar = new javax.swing.JButton();
btProximo = new javax.swing.JButton();
btUltimo = new javax.swing.JButton();
btExcluir = new javax.swing.JButton();
btnPesquisar = new javax.swing.JButton();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Manipular Cadastros de Clientes.");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setName("FrmCadastroClientes"); // NOI18N
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel1.setText("Código:");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel2.setText("Nome:");
txtCodigo.setFont(new java.awt.Font("Dialog", 1, 12));
txtCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txtCodigoFocusLost(evt);
}
});
txtNome.setFont(new java.awt.Font("Dialog", 1, 12));
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel4.setText("Login:");
txtLogin.setFont(new java.awt.Font("Dialog", 1, 12));
jPanel1.setBackground(new java.awt.Color(0, 0, 255));
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("ANALISTAS");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Senha:");
txtSenha.setFont(new java.awt.Font("Dialog", 1, 12));
btNovo.setFont(new java.awt.Font("Tahoma", 1, 11));
btNovo.setText("Novo");
btNovo.setToolTipText("Insere novo registro.");
btNovo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btNovoActionPerformed(evt);
}
});
btPrimeiro.setFont(new java.awt.Font("Tahoma", 1, 11));
btPrimeiro.setToolTipText("Vai para o primeiro registro.");
btPrimeiro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btPrimeiroActionPerformed(evt);
}
});
btAnterior.setFont(new java.awt.Font("Tahoma", 1, 11));
btAnterior.setToolTipText("Vai para o registro anterior.");
btAnterior.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
btAnteriorMouseMoved(evt);
}
});
btAnterior.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btAnteriorActionPerformed(evt);
}
});
btEditar.setFont(new java.awt.Font("Tahoma", 1, 11));
btEditar.setText("Alterar");
btEditar.setToolTipText("Alterar seu registro atual.");
btEditar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btEditarActionPerformed(evt);
}
});
btSalvar.setFont(new java.awt.Font("Tahoma", 1, 11));
btSalvar.setText("Gravar");
btSalvar.setToolTipText("Grava suas alterações.");
btSalvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSalvarActionPerformed(evt);
}
});
btProximo.setFont(new java.awt.Font("Tahoma", 1, 11));
btProximo.setToolTipText("Vai para o próximo registro.");
btProximo.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
btProximoMouseMoved(evt);
}
});
btProximo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btProximoActionPerformed(evt);
}
});
btUltimo.setFont(new java.awt.Font("Tahoma", 1, 11));
btUltimo.setToolTipText("Vai para o ultimo registro.");
btUltimo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btUltimoActionPerformed(evt);
}
});
btExcluir.setFont(new java.awt.Font("Tahoma", 1, 11));
btExcluir.setText("Excluir");
btExcluir.setToolTipText("Exclui seu registro atual. CUIDADO!");
btExcluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btExcluirActionPerformed(evt);
}
});
btnPesquisar.setText("Pesquisar");
btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPesquisarActionPerformed(evt);
}
});
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.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btPrimeiro, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
.addComponent(btNovo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btAnterior, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btProximo, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
.addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btUltimo, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
.addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(txtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(22, 22, 22)
.addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap(18, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPesquisar)))
.addGap(4, 4, 4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(txtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(txtSenha, 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(btNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btAnterior, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btPrimeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btUltimo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btProximo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(51, Short.MAX_VALUE))
);
getAccessibleContext().setAccessibleName("Manipular cadastros de Clientes.");
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-569)/2, (screenSize.height-293)/2, 569, 293);
}// </editor-fold>
private void formWindowClosed(java.awt.event.WindowEvent evt) {
TabelaClientes.desconecta();
}
private void btEditarActionPerformed(java.awt.event.ActionEvent evt) {
try {
// try {
switch (situacaoEdicao) {
case 0:
situacaoEdicao = 2;
exibeBotoes();
break;
case 1:
TabelaClientes.resultset.first();
case 2:
situacaoEdicao = 0;
mostradados();
break;
}
} catch (SQLException ex) {
Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {
Object opcoesBotao[]={"SIM","N?O"};
try {
// String sql = "SELECT * FROM CLIENTEVISITA WHERE CODCLIENTE='" + txtCodigo.getText() + "'";
// TabelaClientes.executeSQL(sql);
// TabelaClientes.resultset.first();
String nome = "Deletar o cliente: " + txtNome.getText() + "?";
int opcaoescolhida = JOptionPane.showOptionDialog(null, nome, "A T E N ? ? O !", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,opcoesBotao,opcoesBotao[1]);
if (opcaoescolhida == JOptionPane.YES_OPTION) {
String sql = "DELETE * FROM ANALISTAS WHERE LOGIN='" + txtLogin.getText() + "'";
int conseguiuexcluir = TabelaClientes.statement.executeUpdate(sql);
if (conseguiuexcluir == 1) {
JOptionPane.showMessageDialog(null, "Exclusão realizada com sucesso!");
TabelaClientes.executeSQL("SELECT * FROM ANALISTAS");
TabelaClientes.resultset.first();
mostradados();
}
} else {
// TabelaClientes.executeSQL("SELECT * FROM CLIENTEVISITA");
mostradados();
return;
}
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null, "Erro ao tentar excluir o registro\n" + erro);
}
}
private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {
try {
switch (situacaoEdicao) {
case 1:
String sqlinsert = "INSERT INTO ANALISTAS ( CODIGO, LOGIN, NMANALISTA, SENHA ) VALUES ('" +
txtCodigo.getText() + "','" +
txtLogin.getText() + "','" +
txtNome.getText() + "','" +
txtSenha.getText() + "')";
TabelaClientes.statement.executeUpdate(sqlinsert);
JOptionPane.showMessageDialog(null, "Dados inseridos com sucesso!");
break;
case 2:
String sql = "UPDATE ANALISTAS SET NMANALISTA='" + txtNome.getText() + "', " +
"SENHA='" + txtSenha.getText() + "', " +
"LOGIN='" + txtLogin.getText() + "' WHERE LOGIN='" + txtLogin.getText() + "'";
TabelaClientes.statement.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Edição realizada com sucesso!");
break;
}
//C?digo para atualizar o ResultSet
TabelaClientes.resultset = TabelaClientes.statement.executeQuery("SELECT * FROM ANALISTAS");
TabelaClientes.resultset.last();
situacaoEdicao = 0;
mostradados();
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null, "Erro ao tentar gravar registro.\n" + erro);
}
}
private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {
txtCodigo.setText("");
txtNome.setText("");
txtSenha.setText("");
txtLogin.setText("");
txtCodigo.requestFocus();
situacaoEdicao = 1;
exibeBotoes();
//txtNome.requestFocus();
//txtCodigo.setEditable(false);
}
private void btProximoMouseMoved(java.awt.event.MouseEvent evt) {
navega = 1;// TODO add your handling code here:
}
private void btAnteriorMouseMoved(java.awt.event.MouseEvent evt) {
navega = 2;// TODO add your handling code here:
}
private void btAnteriorActionPerformed(java.awt.event.ActionEvent evt) {
try {
TabelaClientes.resultset.previous();
{
mostradados();
//navega = 1;
}
} catch (SQLException erro) {
//JOptionPane.showMessageDialog(null, "N?o foi poss?vel ir para o registro anterior!"+erro);
}
exibeBotoes();
}
private void btPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {
try {
TabelaClientes.resultset.first();
{
mostradados();
}
} catch (SQLException erro) {
//JOptionPane.showMessageDialog(null, "N?o foi poss?vel ir para o primeiro registro!"+erro);
}
exibeBotoes();
}
private void btUltimoActionPerformed(java.awt.event.ActionEvent evt) {
try {
TabelaClientes.resultset.last();
{
mostradados();
}
} catch (SQLException erro) {
// JOptionPane.showMessageDialog(null, "N?o foi poss?vel ir para o ?ltimo registro!"+erro);
}
exibeBotoes();
}
private void btProximoActionPerformed(java.awt.event.ActionEvent evt) {
try {
TabelaClientes.resultset.next();
{
mostradados();
//navega = 2;
}
} catch (SQLException erro) {
//JOptionPane.showMessageDialog(null, "N?o foi poss?vel ir para o pr?ximo registro!"+erro);
}
exibeBotoes();
}
private void formKeyPressed(java.awt.event.KeyEvent evt) {
}
private void txtCodigoKeyPressed(java.awt.event.KeyEvent evt) {
}
private void txtNomeKeyPressed(java.awt.event.KeyEvent evt) {
//keyPressed(evt);
}
private void txtBairroKeyPressed(java.awt.event.KeyEvent evt) {
//keyPressed(evt);
}
private void txtCidadeKeyPressed(java.awt.event.KeyEvent evt) {
//keyPressed(evt);
}
private void txtCodigoFocusGained(java.awt.event.FocusEvent evt) {
// LocalizaCliente();
}
private void btLocalizarActionPerformed(java.awt.event.ActionEvent evt) {
new PesquisarPessoas().show();
//LocalizaCliente();
//txtFormaberto.setText("Clientes");
}
private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {
//LocalizaCliente(); // TODO add your handling code here:
}
private void txtCodigoFocusLost(java.awt.event.FocusEvent evt) {
String aux = txtCodigo.getText();
aux = "000000" + aux;
aux = aux.substring(aux.length() - 6);
txtCodigo.setText(aux);
}
private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {
new PesquisarAnalista().show();
dispose();
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if(!strSQL.isEmpty()){
try {
String sql = "SELECT * FROM ANALISTAS WHERE LOGIN ='" + strSQL + "'";
TabelaClientes.executeSQL(sql);
TabelaClientes.resultset.first();
mostradados();
sql = "SELECT * FROM ANALISTAS";
TabelaClientes.executeSQL(sql);
TabelaClientes.resultset.first();
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null, "Nao foi possivel localizar Cliente");
//txtPesquisar.requestFocus();
mostradados();
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Clientes().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btAnterior;
private javax.swing.JButton btEditar;
private javax.swing.JButton btExcluir;
private javax.swing.JButton btNovo;
private javax.swing.JButton btPrimeiro;
private javax.swing.JButton btProximo;
private javax.swing.JButton btSalvar;
private javax.swing.JButton btUltimo;
private javax.swing.JButton btnPesquisar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private java.awt.TextField txtCodigo;
private java.awt.TextField txtLogin;
public static java.awt.TextField txtNome;
private java.awt.TextField txtSenha;
// End of variables declaration
public void mostradados() {
try {
txtCodigo.setText(TabelaClientes.resultset.getString("Codigo"));
txtNome.setText(TabelaClientes.resultset.getString("NmAnalista"));
txtSenha.setText(TabelaClientes.resultset.getString("Senha"));
txtLogin.setText(TabelaClientes.resultset.getString("Login"));
} catch (SQLException erro) {
JOptionPane.showMessageDialog(null,"Oi ===>>> "+ erro);
}
exibeBotoes();
}
public void exibeBotoes() {
// Adiciona os ?cones aos bot?es, exceto ao bot?o editar/cancelar
// que recebe seu ?cone no switch abaixo
ImageIcon IcCancelar = new ImageIcon("./images/cancelar2.gif");
ImageIcon IcEditar = new ImageIcon("./images/editar.gif");
ImageIcon IcSalvar = new ImageIcon("./images/salvar.gif");
ImageIcon IcExcluir = new ImageIcon("./images/excluir.gif");
ImageIcon IcNovo = new ImageIcon("./images/novo.gif");
ImageIcon IcPrimeiro = new ImageIcon("./images/primeiro_registro.gif");
ImageIcon IcUltimo = new ImageIcon("./images/ultimo_registro.gif");
ImageIcon IcAnterior = new ImageIcon("./images/registro_anterior.gif");
ImageIcon IcProximo = new ImageIcon("./images/proximo_registro.gif");
btNovo.setIcon(IcNovo);
btExcluir.setIcon(IcExcluir);
btSalvar.setIcon(IcSalvar);
btAnterior.setIcon(IcAnterior);
btProximo.setIcon(IcProximo);
btPrimeiro.setIcon(IcPrimeiro);
btUltimo.setIcon(IcUltimo);
switch (situacaoEdicao) {
case 0:
btSalvar.setEnabled(false);
btNovo.setEnabled(true);
btExcluir.setEnabled(true);
try {
if (TabelaClientes.resultset.isLast()) {
btPrimeiro.setEnabled(true);
btAnterior.setEnabled(true);
btProximo.setEnabled(false);
btUltimo.setEnabled(false);
} else if (TabelaClientes.resultset.isFirst()) {
btPrimeiro.setEnabled(false);
btAnterior.setEnabled(false);
btProximo.setEnabled(true);
btUltimo.setEnabled(true);
} else {
btPrimeiro.setEnabled(true);
btAnterior.setEnabled(true);
btProximo.setEnabled(true);
btUltimo.setEnabled(true);
}
} catch (SQLException ex) {
Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex);
}
btEditar.setToolTipText("Edita um registro existente.");
btEditar.setText("Editar");
btEditar.setIcon(IcEditar);
txtCodigo.setEditable(false);
txtNome.setEditable(false);
txtSenha.setEditable(false);
txtLogin.setEditable(false);
break;
case 1:
case 2:
btSalvar.setEnabled(true);
btNovo.setEnabled(false);
btExcluir.setEnabled(false);
btPrimeiro.setEnabled(false);
btProximo.setEnabled(false);
btAnterior.setEnabled(false);
btUltimo.setEnabled(false);
btEditar.setToolTipText("Cancelar operação.");
btEditar.setText("Cancelar");
btEditar.setIcon(IcCancelar);
txtCodigo.setEditable(true);
txtNome.setEditable(true);
txtSenha.setEditable(true);
txtLogin.setEditable(true);
break;
}
}
}
