Eu tenho um Jframe chamado login com três botões (Entrar, Cadastrar e Sair)
o Botão cadastrar era pra chamar um outro JFrame chamado cadastro, onde o usuário iria criar seu cadastro. Porem ao executar o código e clicar no botão cadastro apareciam vários erros na saída do netbeans.
Código-Fonte do login
package Grafica;
import Controller.ControllerUsuario;
import Modelo.ModeloSessaoUsuario;
import Modelo.ModeloUsuario;
import javax.swing.JOptionPane;
/**
*
* author 02799485227
*/
public class Login extends javax.swing.JFrame {
ModeloUsuario modeloUsuario = new ModeloUsuario();
ControllerUsuario controllerUsuario = new ControllerUsuario();
/**
* Creates new form Login
*/
public Login() {
initComponents();
}
private void BtnSairActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void BtnEntrarActionPerformed(java.awt.event.ActionEvent evt) {
autenticar();
new PedidoTamanho().setVisible(true);
dispose();
}
private void autenticar() {
modeloUsuario.setEmail(this.jEmail.getText());
modeloUsuario.setSenha(this.jSenha.getText());
if (controllerUsuario.getUsuarioController(modeloUsuario)) {
ModeloSessaoUsuario.nome = controllerUsuario.getUsuarioController(modeloUsuario.getEmail()).getNome();
PedidoTamanho pedido = new PedidoTamanho();
pedido.setVisible(true);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "Email/Senha inválida.", "Aviso", JOptionPane.WARNING_MESSAGE);
}
}
private void jSenhaActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jEmailActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BtnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
Cadastro cad = new Cadastro();
cad.setVisible(true);
dispose();
}
/**
* param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton BtnCadastrar;
private javax.swing.JButton BtnEntrar;
private javax.swing.JButton BtnSair;
private javax.swing.JTextField jEmail;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jSenha;
// End of variables declaration
}
Código-Fonte JFrame Cadastro
package Grafica;
import Controller.ControllerUsuario;
import Modelo.ModeloUsuario;
import javax.swing.JOptionPane;
/**
*
* author 04559966281
*/
public class Cadastro extends javax.swing.JFrame {
ModeloUsuario modeloUsuario = new ModeloUsuario();
ControllerUsuario controllerUsuario = new ControllerUsuario();
/**
* Creates new form Cadastro
*/
public Cadastro() {
initComponents();
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jNome = new javax.swing.JTextField();
jEmail = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
BtnSair = new javax.swing.JButton();
BtnCadastrar = new javax.swing.JButton();
BtnVoltar = new javax.swing.JButton();
jSenha = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Nome");
jLabel2.setText("E-mail");
jLabel3.setText("Senha");
jNome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jNomeActionPerformed(evt);
}
});
jLabel4.setText("Cadastrar");
BtnSair.setText("Sair");
BtnSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnSairActionPerformed(evt);
}
});
BtnCadastrar.setText("Cadastrar");
BtnCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnCadastrarActionPerformed(evt);
}
});
BtnVoltar.setText("Voltar");
BtnVoltar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnVoltarActionPerformed(evt);
}
});
jSenha.setText("jPasswordField1");
jSenha.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jSenhaMouseClicked(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()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jEmail))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSenha))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jNome, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(288, 288, 288)
.addComponent(jLabel4)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(116, 116, 116)
.addComponent(BtnSair)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
.addComponent(BtnVoltar)
.addGap(77, 77, 77)
.addComponent(BtnCadastrar)
.addGap(160, 160, 160))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jLabel4)
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jNome, 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.BASELINE)
.addComponent(jLabel2)
.addComponent(jEmail, 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.BASELINE)
.addComponent(jLabel3)
.addComponent(jSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 140, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BtnSair)
.addComponent(BtnCadastrar)
.addComponent(BtnVoltar))
.addGap(87, 87, 87))
);
pack();
}// </editor-fold>
private void jNomeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BtnSairActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void BtnVoltarActionPerformed(java.awt.event.ActionEvent evt) {
new Login().setVisible(true);
dispose();
}
private void BtnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
salvarCliente();
}
private void jSenhaMouseClicked(java.awt.event.MouseEvent evt) {
jSenha.setText("");
}
private boolean salvarCliente() {
modeloUsuario.setNome(this.jNome.getText());
modeloUsuario.setEmail(this.jEmail.getText());
modeloUsuario.setSenha(this.jSenha.getText());
if (controllerUsuario.salvarUsuarioController(modeloUsuario)>0) {
JOptionPane.showMessageDialog(this, "Registro gravado com sucesso!");
return true;
} else {
JOptionPane.showMessageDialog(this, "Erro ao gravar os dados!", "ERRO", JOptionPane.ERROR_MESSAGE);
return false;
}
}
/**
* 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(Cadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Cadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Cadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Cadastro.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 Cadastro().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton BtnCadastrar;
private javax.swing.JButton BtnSair;
private javax.swing.JButton BtnVoltar;
private javax.swing.JTextField jEmail;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField jNome;
private javax.swing.JPasswordField jSenha;
// End of variables declaration
}