Estou tentando “chamar” Getters e Setters de uma classe modelo. Entretanto, o Netbeans fica acusando erro, mesmo eu importando e criando os métodos especiais, sempre aparece uma pequena mensagem de erro.
O erro ocorre quando tento colocar no botão de Cadastro, de um Formulário, o parametro.setter(txt.getter(é aqui em que ocorre o erro)).
Já importei a classe modelo, importei a classe de DAO, mas o erro ainda continua.
Aqui estão os códigos:
Painel de Cadastro:
package cemep;
import DAO.FuncionarioDAO;
import modelos.*;
public class funcionario extends javax.swing.JFrame {
/**
* Creates new form funcionario
*/
public funcionario() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
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();
txtDataAdmissao = new javax.swing.JTextField();
txtSalario = new javax.swing.JTextField();
txtDepartamento = new javax.swing.JTextField();
txtLogin = new javax.swing.JTextField();
txtSenha = new javax.swing.JTextField();
txtAcesso = new javax.swing.JTextField();
btnCadastrar = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel8 = new javax.swing.JLabel();
txtNome = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
txtEmail = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
txtMatricula = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
txtDataNasc = new javax.swing.JTextField();
jLabel2.setText("DATA DE ADMISSÃO");
jLabel3.setText("SALARIO");
jLabel4.setText("DEPARTAMENTO");
jLabel5.setText("USUÁRIO");
jLabel6.setText("SENHA");
jLabel7.setText("ACESSO");
btnCadastrar.setText("Cadastrar");
btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCadastrarActionPerformed(evt);
}
});
jButton2.setText("Editar");
jButton3.setText("Adicionar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Excluir");
jLabel8.setText("NOME");
txtNome.setName("txtNome"); // NOI18N
jLabel9.setText("EMAIL");
txtEmail.setName("txtEmail"); // NOI18N
jLabel10.setText("MATRICULA");
txtMatricula.setName("txtMatricula"); // NOI18N
jLabel11.setText("DATA DE NASCIMENTO");
txtDataNasc.setName("txtDataNasc"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel3)
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel5)
.addComponent(jLabel4)
.addComponent(jLabel2)
.addComponent(txtDataAdmissao, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
.addComponent(txtSalario)
.addComponent(txtDepartamento)
.addComponent(txtLogin)
.addComponent(txtSenha)
.addComponent(txtAcesso))
.addGap(168, 168, 168)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(txtDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(btnCadastrar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(78, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtDataAdmissao, 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(jLabel9)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtSalario, 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.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(1, 1, 1)
.addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel11)
.addGap(1, 1, 1)
.addComponent(txtDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(1, 1, 1)
.addComponent(txtDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addGap(1, 1, 1)
.addComponent(txtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtAcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 99, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCadastrar)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
ModeloFuncionario f = new ModeloFuncionario();
FuncionarioDAO dao = new FuncionarioDAO();
f.setMatricula(String.setString(txtMatricula.**getMatricula**())); //É em getMatricula e getNome em que ocorrem esse erro
f.setNome(String.parseString(txtNome.**getNome**()));
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new funcionario().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnCadastrar;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
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.JTextField txtAcesso;
private javax.swing.JTextField txtDataAdmissao;
private javax.swing.JTextField txtDataNasc;
private javax.swing.JTextField txtDepartamento;
private javax.swing.JTextField txtEmail;
private javax.swing.JTextField txtLogin;
private javax.swing.JTextField txtMatricula;
private javax.swing.JTextField txtNome;
private javax.swing.JTextField txtSalario;
private javax.swing.JTextField txtSenha;
// End of variables declaration
}
DAO do Funcionário
package DAO;
import cemep.AbrirConexao;
import cemep.funcionario;
import java.sql.*;
import javax.swing.JOptionPane;
import modelos.ModeloFuncionario;
public class FuncionarioDAO {
PreparedStatement stmt = null;
public void cadastrarFuncionario(ModeloFuncionario f) throws SQLException, ClassNotFoundException{
Connection con = AbrirConexao.abrirConexao();
try{
stmt = con.prepareStatement("INSERT INTO funcionario(matricula, nome, datanasc, cpf, cep, cidade, estado, bairro, endereco, numCasa, dataAdmissao, salario, departamento, idLogin, email) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
stmt.setString(1,f.getMatricula());
stmt.setString(2,f.getNome());
stmt.setDate(3, f.getDatanasc());
stmt.setString(4, f.getCpf());
stmt.setString(5, f.getCep());
stmt.setString(6, f.getCidade());
stmt.setString(7, f.getEstado());
stmt.setString(8, f.getBairro());
stmt.setString(9, f.getEndereco());
stmt.setInt(10, f.getNumCasa());
stmt.setDate(11, f.getDataAdmissao());
stmt.setFloat(12, f.getSalario());
stmt.setInt(13, f.getDepartamento());
stmt.setInt(14, f.getIdLogin());
stmt.setString(15, f.getEmail());
stmt.executeUpdate();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Não foi possível realizar o cadastro");
}
}
}
Classe Modelo:
package modelos;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.Date;
import java.sql.ResultSet;
public class ModeloFuncionario {
private int id;
private int numCasa;
private int departamento;
private int idLogin;
private String matricula;
private String nome;
private String cpf;
private String cep;
private String cidade;
private String estado;
private String bairro;
private String endereco;
private String email;
private Date datanasc;
private Date dataAdmissao;
private float salario;
private Connection conectar = null;
private PreparedStatement pst = null;
private ResultSet rs = null;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the numCasa
*/
public int getNumCasa() {
return numCasa;
}
/**
* @param numCasa the numCasa to set
*/
public void setNumCasa(int numCasa) {
this.numCasa = numCasa;
}
/**
* @return the departamento
*/
public int getDepartamento() {
return departamento;
}
/**
* @param departamento the departamento to set
*/
public void setDepartamento(int departamento) {
this.departamento = departamento;
}
/**
* @return the idLogin
*/
public int getIdLogin() {
return idLogin;
}
/**
* @param idLogin the idLogin to set
*/
public void setIdLogin(int idLogin) {
this.idLogin = idLogin;
}
/**
* @return the matricula
*/
public String getMatricula() {
return matricula;
}
/**
* @param matricula the matricula to set
*/
public void setMatricula(String matricula) {
this.matricula = matricula;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the cpf
*/
public String getCpf() {
return cpf;
}
/**
* @param cpf the cpf to set
*/
public void setCpf(String cpf) {
this.cpf = cpf;
}
/**
* @return the cep
*/
public String getCep() {
return cep;
}
/**
* @param cep the cep to set
*/
public void setCep(String cep) {
this.cep = cep;
}
/**
* @return the cidade
*/
public String getCidade() {
return cidade;
}
/**
* @param cidade the cidade to set
*/
public void setCidade(String cidade) {
this.cidade = cidade;
}
/**
* @return the estado
*/
public String getEstado() {
return estado;
}
/**
* @param estado the estado to set
*/
public void setEstado(String estado) {
this.estado = estado;
}
/**
* @return the bairro
*/
public String getBairro() {
return bairro;
}
/**
* @param bairro the bairro to set
*/
public void setBairro(String bairro) {
this.bairro = bairro;
}
/**
* @return the endereco
*/
public String getEndereco() {
return endereco;
}
/**
* @param endereco the endereco to set
*/
public void setEndereco(String endereco) {
this.endereco = endereco;
}
/**
* @return the datanasc
*/
public Date getDatanasc() {
return datanasc;
}
/**
* @param datanasc the datanasc to set
*/
public void setDatanasc(Date datanasc) {
this.datanasc = datanasc;
}
/**
* @return the dataAdmissao
*/
public Date getDataAdmissao() {
return dataAdmissao;
}
/**
* @param dataAdmissao the dataAdmissao to set
*/
public void setDataAdmissao(Date dataAdmissao) {
this.dataAdmissao = dataAdmissao;
}
/**
* @return the salario
*/
public float getSalario() {
return salario;
}
/**
* @param salario the salario to set
*/
public void setSalario(float salario) {
this.salario = salario;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
}