0
I was programming, so far so good, but when 'getar' +txt_endereco.gettext()+ gives cannot find Symbol, when I go 'setar' the same thing 'txt_endereco.setText(model.getValueAt(indexrow, 4). toString()); '
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controleescolar;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class detalhesescolares extends javax.swing.JFrame {
/**
* Creates new form detalhesescolares
*/
public detalhesescolares() {
initComponents();
setLocationRelativeTo(null);
getdata();
chk();
}
String host="jdbc:derby://localhost:1527/Controle Escolar";
String usuario="root";
String senha="admin";
private void chk()
{
try
{
Connection con= DriverManager.getConnection(host, usuario, senha);
Statement stmt= con.createStatement();
String querry="select * from DetalhesEscolares";
ResultSet rs= stmt.executeQuery(querry);
if(!rs.next())
{
txt_botao1.setEnabled(false);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error!"+e);
}
}
private void getdata()
{
DefaultTableModel model = (DefaultTableModel)txt_tabela.getModel();
model.setRowCount(0);
try
{
Connection con= DriverManager.getConnection(host, usuario, senha);
Statement stmt= con.createStatement();
String query="select * from DetalhesEscolares";
ResultSet rs= stmt.executeQuery(query);
while(!rs.next())
{
model.addRow(new Object[]{rs.getInt("id"),rs.getString("nome"),rs.getString("telefone"),rs.getString("email"),rs.getString("endereco"),rs.getString("site")});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error!"+e);
}
}
/**
* 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() {
jScrollPane1 = new javax.swing.JScrollPane();
txt_tabela = new javax.swing.JTable();
txt_site = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
txt_nome = new javax.swing.JTextField();
txt_tell = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txt_email = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txt_botao1 = new javax.swing.JButton();
txt_botao2 = new javax.swing.JButton();
txt_botao3 = new javax.swing.JButton();
txt_endereco = new javax.swing.JScrollPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
txt_tabela.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"NOME", "TELEFONE", "EMAIL", "ENDEREÇO", "SITE"
}
));
txt_tabela.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
txt_tabelaMouseClicked(evt);
}
});
jScrollPane1.setViewportView(txt_tabela);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel1.setText("Nome:");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel2.setText("Telefone:");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel3.setText("Email:");
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel4.setText("Site:");
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel5.setText("Endereço:");
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
jLabel6.setText("Detalhes Escolares");
txt_botao1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
txt_botao1.setText("CRIAR");
txt_botao1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_botao1ActionPerformed(evt);
}
});
txt_botao2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
txt_botao2.setText("ATUALIZAR");
txt_botao2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_botao2ActionPerformed(evt);
}
});
txt_botao3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
txt_botao3.setText("FECHAR");
txt_botao3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txt_botao3ActionPerformed(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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_nome, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
.addComponent(txt_tell, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txt_email, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5))
.addGroup(layout.createSequentialGroup()
.addGap(83, 83, 83)
.addComponent(txt_botao1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(40, 40, 40)
.addComponent(txt_botao2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel4)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 42, Short.MAX_VALUE)
.addComponent(txt_botao3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(80, 80, 80))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_site, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addComponent(txt_endereco))
.addGap(0, 0, Short.MAX_VALUE))))))
.addGroup(layout.createSequentialGroup()
.addGap(183, 183, 183)
.addComponent(jLabel6)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txt_endereco)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_nome, 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(txt_tell, 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.BASELINE)
.addComponent(jLabel3)
.addComponent(txt_email, 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(txt_site, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_botao2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txt_botao3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(txt_botao1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void txt_botao1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Connection con= DriverManager.getConnection(host,usuario,senha);
Statement stmt= con.createStatement();
String query="insert into DetalhesEscolares (nome,telefone,email,endereco,site) values('"+txt_nome.getText()+"','"+txt_tell.getText()+"','"+txt_email.getText()+"','"+txt_endereco.getText()+"','"+txt_site.getText()+"') ";
stmt.execute(query);
JOptionPane.showMessageDialog(null, "Salvo!");
getdata();
vazio();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error!"+e);
}
}
String id;
private void txt_tabelaMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here: // TODO add your handling code here:
int indexrow= txt_tabela.getSelectedRow();
DefaultTableModel model = (DefaultTableModel)txt_tabela.getModel();
id=model.getValueAt(indexrow, 0).toString();
txt_nome.setText(model.getValueAt(indexrow, 1).toString());
txt_tell.setText(model.getValueAt(indexrow, 2).toString());
txt_email.setText(model.getValueAt(indexrow, 3).toString());
txt_endereco.setText(model.getValueAt(indexrow, 4).toString());
txt_site.setText(model.getValueAt(indexrow, 5).toString());
}
private void txt_botao2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(id!=null)
{
try{
Connection con= DriverManager.getConnection(host,usuario,senha);
Statement stmt= con.createStatement();
String query="update DetalhesEscolares set nome='"+txt_nome.getText()+"',telefone='"+txt_tell.getText()+"',email='"+txt_email.getText()+"',endereco='"+txt_endereco.getText()+"',site='"+txt_site.getText()+"' where id="+id+" ";
stmt.execute(query);
JOptionPane.showMessageDialog(null, "Atualizado!");
getdata();
vazio();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Selecione um item para atualizar!");
}
}
else
{
JOptionPane.showMessageDialog(null, "Selecione um item para atualizar!");
}
}
private void txt_botao3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void vazio()
{
id=null;
txt_nome.setText(null);
txt_tell.setText(null);
txt_email.setText(null);
txt_endereco.setText(null);
txt_site.setText(null);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* 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(detalhesescolares.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(detalhesescolares.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(detalhesescolares.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(detalhesescolares.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new detalhesescolares().setVisible(true);
}
});
}
// Variables declaration - do not modify
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.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton txt_botao1;
private javax.swing.JButton txt_botao2;
private javax.swing.JButton txt_botao3;
private javax.swing.JTextField txt_email;
private javax.swing.JScrollPane txt_endereco;
private javax.swing.JTextField txt_nome;
private javax.swing.JTextField txt_site;
private javax.swing.JTable txt_tabela;
private javax.swing.JTextField txt_tell;
// End of variables declaration
}
solved, switched to texbox and managed to catch the input and exit
– Marcos Antônio