Intendi essa parte Obrigado, mas está complicado a situação aqui, pois creio que estou fazendo certo…
olha meu codigo
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.banhotosa.View;
import br.com.banhotosa.Dao.ClienteDAO;
import br.com.banhotosa.Dao.UsuarioDAO;
import br.com.banhotosa.Model.Cliente;
import br.com.banhotosa.Model.Usuario;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author Rafael Almeida
*/
public class FrmaddUsuario extends javax.swing.JDialog {
private final UsuarioDAO dao;
private final FrmUsuario controle;
/**
* Creates new form frmaddUsuario
*/
public FrmaddUsuario(java.awt.Frame parent, boolean modal, UsuarioDAO dao, FrmUsuario controle) {
super(parent, modal);
this.dao = dao; // aqui já estou passsando ele
this.controle = controle;
initComponents();
}
FrmaddUsuario(JFrame jFrame, boolean b, ClienteDAO dao, Cliente get) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtconfirmasenha = new javax.swing.JPasswordField();
txtsenha = new javax.swing.JPasswordField();
txtlogin = new javax.swing.JTextField();
txtcargo = new javax.swing.JTextField();
txtnome = new javax.swing.JTextField();
btOk = new javax.swing.JButton();
jToggleButton1 = new javax.swing.JToggleButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("AtualizarUsuário");
setResizable(false);
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jLabel1.setText("Nome:");
jLabel2.setText("Cargo:");
jLabel3.setText("Login:");
jLabel4.setText("Senha:");
jLabel5.setText("Confirma Senha:");
txtsenha.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtsenhaActionPerformed(evt);
}
});
txtcargo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtcargoActionPerformed(evt);
}
});
btOk.setText("Ok");
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
jToggleButton1.setText("Cancel");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
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(18, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtsenha, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtconfirmasenha, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txtlogin, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
.addComponent(txtcargo, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtnome, javax.swing.GroupLayout.Alignment.LEADING))))
.addGap(12, 12, 12))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(btOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(96, 96, 96))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtnome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtcargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtlogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(txtconfirmasenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtsenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btOk)
.addComponent(jToggleButton1))
.addContainerGap(18, Short.MAX_VALUE))
);
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()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
setBounds(100, 100, 388, 267);
}// </editor-fold>
private void txtcargoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtsenhaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
setVisible(false);
// TODO add your handling code here:
}
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {
if (txtnome.getText().equals("")) {
JOptionPane.showMessageDialog(this,"O campo Nome precisa estar preenchido", "Validação",JOptionPane.ERROR_MESSAGE);
return;
}
if (txtlogin.getText().equals("")) {
JOptionPane.showMessageDialog(this,"O campo Login precisa estar preenchido", "Validação",JOptionPane.ERROR_MESSAGE);
return;
}
if (txtsenha.getText().equals("")) {
JOptionPane.showMessageDialog(this,"O campo Senha precisa estar preenchido", "Validação",JOptionPane.ERROR_MESSAGE);
return;
}
if(!txtsenha.getText().equals(txtconfirmasenha.getText())){
JOptionPane.showMessageDialog(this, "As senhas devem ser iguais", "Erro",JOptionPane.ERROR_MESSAGE);
return;
}
int result = JOptionPane.showConfirmDialog(this, "Você tem certeza?", "Adcionar Usuário",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
if (result==2) return;
Usuario usuario = new Usuario();
usuario.setNome_usuario(txtnome.getText());
usuario.setCargo(txtcargo.getText());
usuario.setLogin(txtlogin.getText());
usuario.setSenha(txtsenha.getText());
try {
dao.salvar(usuario); // então aqui não preciso de fazer UsuarioDAO dao = new UsuarioDAO();
controle.carregartabela();
controle.setStatus("Usuário Adiconado");
setVisible(false);
System.out.println("Chegou até aqui");//não deve chegar até aqui
} catch (Exception ex) { //catch (SQLException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Erro ao Adicionar usuário" + ex, "Erro",JOptionPane.ERROR_MESSAGE);
}
return;
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
FrmaddUsuario dialog = new FrmaddUsuario(new javax.swing.JFrame(), true, new UsuarioDAO(), null);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btOk;
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.JToggleButton jToggleButton1;
private javax.swing.JTextField txtcargo;
private javax.swing.JPasswordField txtconfirmasenha;
private javax.swing.JTextField txtlogin;
private javax.swing.JTextField txtnome;
private javax.swing.JPasswordField txtsenha;
// End of variables declaration
}
estou certo?