Ola, estou tendo o prolema do título quando tento executar uma função de validar dados ao clicar no botão de login.
Eu vi que esse é um erro recorrente porém mesmo vendo os outros tópicos não consegui uma solução
Segue abaixo o código do form
package formularios;
import clases.Dados;
import clases.Usuario;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class frmLogin extends javax.swing.JFrame {
Dados msDados;
public void setDados(Dados msDados){
this.msDados = msDados;
}
public frmLogin() {
this.setLocationRelativeTo(null);
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() {
jFrame1 = new javax.swing.JFrame();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
txtUsuario = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtSenha = new javax.swing.JPasswordField();
btnLogin = new javax.swing.JButton();
btnSair = new javax.swing.JButton();
jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jFrame1.setTitle("Sistema Login:");
jFrame1.setResizable(false);
jLabel2.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 0, 51));
jLabel2.setText("Usuário:");
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jFrame1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(55, Short.MAX_VALUE))
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jFrame1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(378, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Sistema Login:");
setResizable(false);
jLabel1.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 0, 51));
jLabel1.setText("Usuário:");
jLabel3.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 0, 51));
jLabel3.setText("Senha:");
btnLogin.setText("Login");
btnLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLoginActionPerformed(evt);
}
});
btnSair.setText("Sair");
btnSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSairActionPerformed(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(25, 25, 25)
.addComponent(jLabel1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(btnLogin)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSair))
.addComponent(txtUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
.addComponent(txtSenha))
.addContainerGap(39, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnLogin)
.addComponent(btnSair))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jLabel1.getAccessibleContext().setAccessibleName("usuario");
jLabel1.getAccessibleContext().setAccessibleDescription("");
pack();
}// </editor-fold>
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
/*if (!msDados.validarUsuario(txtUsuario.getText(),
new String(txtSenha.getPassword()))) {
JOptionPane.showMessageDialog(rootPane, "Usuario ou Senha Incorretos");
return;
}*/
if (meusDados.validarUsuario(txtUsuario.getText(),
new String(txtSenha.getPassword()))) {
JOptionPane.showMessageDialog(rootPane, "Usuario ou Senha Incorretos");
return;
}
frmPrincipal meuPrincipal = new frmPrincipal();
this.setVisible(false);
meuPrincipal.setExtendedState(JFrame.MAXIMIZED_BOTH);
meuPrincipal.setVisible(true);
}
/**
* @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(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(frmLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(frmLogin.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 frmLogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnLogin;
private javax.swing.JButton btnSair;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField2;
private javax.swing.JPasswordField txtSenha;
private javax.swing.JTextField txtUsuario;
// End of variables declaration
}
e o código da classe
/*
* 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 clases;
import javax.swing.JOptionPane;
/**
*
* @author a
*/
public class Dados {
Usuario msUsuarios[] = new Usuario[50];
int conUsu = 0;
public Dados() {
Usuario mUsuario = new Usuario("san", "san1", "san2", "123", "1");
msUsuarios[conUsu] = mUsuario;
}
public boolean validarUsuario(String usuario, String senha) {
boolean aux = false;
for (int i = 0; i < conUsu; i++) {
if (msUsuarios[i].getIdUsuario().equals(usuario) && msUsuarios[i].getSenha().equals(senha)) {
return true;
}
}
return false;
}
}