Continuando a discussão de Problema com a arquitetura MVC em Java:
Model.BO:
package Model.BO;
import Model.DAO.CadastroDAO;
import Model.VO.UsuarioVO;
public class CadastroBO {
private CadastroDAO cadastroDao;
public CadastroBO() {
cadastroDao = new CadastroDAO();
}
public boolean cadastrarUsuario(UsuarioVO usuario) {
try{
if(usuario.getNome()==null||usuario.getNome().isEmpty()||
usuario.getSobrenome()==null||usuario.getSobrenome().isEmpty()||
usuario.getDataNascimento()==null||usuario.getDataNascimento().isEmpty()||
usuario.getNomeUsuario()==null||usuario.getNomeUsuario().isEmpty()||usuario.getSenha()==null||
usuario.getSenha().isEmpty()||usuario.getGrauEscola()==null||
!usuario.getGrauEscola().equals("Escolha uma das opções"))
{
return false;
}
cadastroDao.cadastrarUsuario(usuario);
return true;
}catch(Exception e)
{
e.printStackTrace();
return false;
}
}
}
Controller:
package Controller;
import Model.BO.CadastroBO;
import Model.VO.UsuarioVO;
import View.CadastroConcluido;
import View.CadastroIndeferido;
import View.CadastroView;
public class CadastroController {
private CadastroView cadastroView;
private CadastroBO cadastroBO;
public CadastroController(CadastroView loginView) {
this.cadastroView = loginView;
cadastroBO = new CadastroBO();
loginView.btnVoltaLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnVoltaLoginActionPerformed(evt);
}
});
loginView.txtNome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomeActionPerformed(evt);
}
});
loginView.txtSobrenome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtSobrenomeActionPerformed(evt);
}
});
loginView.BoxGrau.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BoxGrauActionPerformed(evt);
}
});
loginView.txtNomeUsuario.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomeUsuarioActionPerformed(evt);
}
});
loginView.verSenha.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
verSenhaMousePressed(evt);
}
});
loginView.naoVerSenha.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
naoVerSenhaMousePressed(evt);
}
});
loginView.verSenhaConfirma.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
verSenhaConfirmaMousePressed(evt);
}
});
loginView.naoVerSenhaConfirma.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
naoVerSenhaConfirmaMousePressed(evt);
}
});
}
public void btnVoltaLoginActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnVoltaLoginActionPerformed
// TODO add your handling code here:
String nome = cadastroView.txtNome.getText().toString();
String sobrenome = cadastroView.txtSobrenome.getText().toString();
String datanasc = cadastroView.jFormattedTextField1.getText().toString();
String grauescola = cadastroView.BoxGrau.getSelectedItem().toString();
String nomeUsuario = cadastroView.txtNomeUsuario.getText().toString();
String senha = new String(cadastroView.pwdSenha.getPassword());
UsuarioVO usuario = new UsuarioVO();
usuario.setNome(nome);
usuario.setSobrenome(sobrenome);
usuario.setDataNascimento(datanasc);
usuario.setGrauEscola(grauescola);
usuario.setNomeUsuario(nomeUsuario);
usuario.setSenha(senha);
boolean cadastrado = cadastroBO.cadastrarUsuario(usuario);
if (cadastrado) {
CadastroConcluido concluido = new CadastroConcluido();
concluido.setVisible(true);
}else {
CadastroIndeferido indef = new CadastroIndeferido();
indef.setVisible(true);
}
}
public void txtNomeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_txtNomeActionPerformed
// TODO add your handling code here:
}// GEN-LAST:event_txtNomeActionPerformed
private void txtSobrenomeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_txtSobrenomeActionPerformed
// TODO add your handling code here:
}// GEN-LAST:event_txtSobrenomeActionPerformed
private void txtNomeUsuarioActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_txtNomeUsuarioActionPerformed
// TODO add your handling code here:
}// GEN-LAST:event_txtNomeUsuarioActionPerformed
private void verSenhaMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_verSenhaMousePressed
cadastroView.naoVerSenha.setVisible(true);
cadastroView.verSenha.setVisible(false);
cadastroView.pwdSenha.setEchoChar((char) 0);
}// GEN-LAST:event_verSenhaMousePressed
private void naoVerSenhaMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_naoVerSenhaMousePressed
cadastroView.verSenha.setVisible(true);
cadastroView.naoVerSenha.setVisible(false);
cadastroView.pwdSenha.setEchoChar('*');
}// GEN-LAST:event_naoVerSenhaMousePressed
public void verSenhaConfirmaMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_verSenhaConfirmaMousePressed
cadastroView.naoVerSenhaConfirma.setVisible(true);
cadastroView.verSenhaConfirma.setVisible(false);
CadastroView.pwdSenhaConfima.setEchoChar((char) 0);
}// GEN-LAST:event_verSenhaConfirmaMousePressed
public void naoVerSenhaConfirmaMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_naoVerSenhaConfirmaMousePressed
cadastroView.verSenhaConfirma.setVisible(true);
cadastroView.naoVerSenhaConfirma.setVisible(false);
CadastroView.pwdSenhaConfima.setEchoChar('*');
}// GEN-LAST:event_naoVerSenhaConfirmaMousePressed
private void BoxGrauActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_BoxGrauActionPerformed
// TODO add your handling code here:
}// GEN-LAST:event_BoxGrauActionPerformed
}// GEN-LAST:event_btnVoltaLoginActionPerformed