Galera tenho um Logim que esta funcionando em partes
Bem tecnicamente ele so autentifica com o primeiro usuario do BD ele nao verifica o segundo, terceiro, e por assim adiante
me ajudem a fazer funcionar corretamente
[code]package Ensino;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.OutputStreamWriter;
import java.sql.SQLException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.text.Document;
public class LoginFrame extends javax.swing.JFrame {
DesktopEnsino desk;
private JPanel Painel; private JPanel pnLogo;
private JLabel lblLogo;
private JLabel lblSenha; private JLabel lblLogin;
private JButton btnOk; private JButton btnCancelar;
private JPasswordField pswSenha; private JTextField txfLogin;
public LoginFrame() {
try {
ConexaoMySql.getConexaoMySql();
this.setPreferredSize(new java.awt.Dimension(300, 400));
BorderLayout thisLayout = new BorderLayout();
getContentPane().setLayout(thisLayout);
this.setResizable(false);
this.setTitle("CADASTRO DE ALUNOS");
getContentPane().setBackground(new java.awt.Color(0,0,0));
this.setFont(new java.awt.Font("Algerian",1,18));
this.setLocation(new java.awt.Point(200, 200));
{
pnLogo = new JPanel();
BorderLayout pnLogoLayout = new BorderLayout();
getContentPane().add(pnLogo, BorderLayout.CENTER);
pnLogo.setLayout(pnLogoLayout);
pnLogo.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
pnLogo.setPreferredSize(new java.awt.Dimension(286, 247));
{
ImageIcon icon = new ImageIcon("Imagens/smallville.jpg");
lblLogo = new JLabel(icon, JLabel.CENTER);
pnLogo.add(lblLogo, BorderLayout.CENTER);
lblLogo.setBounds(5, 3, 280, 243);
lblLogo.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
lblLogo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Imagens/smallville.jpg")));
}
}
{
Painel = new JPanel();
getContentPane().add(Painel, BorderLayout.SOUTH);
Painel.setLayout(null);
Painel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0,0,0)));
Painel.setPreferredSize(new java.awt.Dimension(275, 120));
{
lblLogin = new JLabel();
Painel.add(lblLogin);
lblLogin.setText("Login");
lblLogin.setBounds(7, 6, 48, 28);
lblLogin.setFont(new java.awt.Font("Cambria",1,14));
lblLogin.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
}
{
lblSenha = new JLabel();
Painel.add(lblSenha);
lblSenha.setText("Senha");
lblSenha.setBounds(7, 40, 48, 28);
lblSenha.setFont(new java.awt.Font("Cambria",1,14));
lblSenha.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
}
{
txfLogin = new JTextField();
Painel.add(txfLogin);
txfLogin.setDocument(new LimitaFieldMaiusculo(20, true));
txfLogin.setBounds(60, 6, 196, 29);
txfLogin.setFont(new java.awt.Font("Cambria",1,14));
txfLogin.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
txfLogin.setToolTipText("ENTRE COM O SEU USUARIO");
}
{
pswSenha = new JPasswordField();
Painel.add(pswSenha);
pswSenha.setDocument(new LimitaFieldMaiusculo(10, true));
pswSenha.setBounds(60, 40, 196, 29);
pswSenha.setFont(new java.awt.Font("Cambria",1,14));
pswSenha.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
pswSenha.setToolTipText("ENTRE COM A SUA SENHA");
}
{
btnOk = new JButton();
Painel.add(btnOk);
btnOk.setText("OK");
btnOk.setBounds(63, 78, 97, 29);
btnOk.setToolTipText("FAZER LOGIN");
btnOk.setMnemonic(java.awt.event.KeyEvent.VK_O);
btnOk.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try { //aki começa a logica da parte de conexao
ConexaoMySql.resultSet.next();
if(txfLogin.getText().equals(ConexaoMySql.resultSet.getString("Usuario"))){
if (new String (pswSenha.getPassword()).equals(ConexaoMySql.resultSet.getString("Senha"))){
setVisible(false);
desk = new DesktopEnsino();
desk.setVisible(true);
pnInformacao.lblNomeUsuario.setText(ConexaoMySql.resultSet.getString("Usuario"));
pnInformacao.lblTipoUsuario.setText(ConexaoMySql.resultSet.getString("Grupo"));
}else{
JOptionPane.showMessageDialog(null, "Senha Inválida");
}
}else{
JOptionPane.showMessageDialog(null, "Usuário Inválido");
}
}catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
{
btnCancelar = new JButton();
Painel.add(btnCancelar);
btnCancelar.setText("CANCELAR");
btnCancelar.setBounds(160, 78, 97, 29);
// btnCancelar.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0,0,0)));
btnCancelar.setToolTipText("CANCELAR LOGIN");
btnCancelar.setMnemonic(java.awt.event.KeyEvent.VK_ESCAPE);
btnCancelar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Object[] options = new Object[2];
JButton btnSim = new JButton("Sim");
btnSim.setToolTipText("CONFIRMA CANCELAMENTO DE LOGIN");
btnSim.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
options[0] = btnSim;
options[1] = "Não";
JOptionPane.showOptionDialog(null, "Deseja realmente encerrar a aplicação?", "Atenção",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
}
});
}
}
this.setSize(303, 406);
} catch (Exception e) {
e.printStackTrace();
}
}
}
[/code]