45 lines
1.5 KiB
Java
45 lines
1.5 KiB
Java
|
import javax.swing.*;
|
||
|
import java.awt.event.ActionEvent;
|
||
|
import java.awt.event.ActionListener;
|
||
|
|
||
|
public class ventana1 {
|
||
|
JPanel panel;
|
||
|
private JTextField usuariol;
|
||
|
private JButton iniciarBoton;
|
||
|
private JButton registerBoton;
|
||
|
private JPasswordField contrasenal;
|
||
|
private JLabel usuarioLabel;
|
||
|
private JLabel contrasenaLabel;
|
||
|
private JLabel inicioText;
|
||
|
|
||
|
public ventana1() {
|
||
|
iniciarBoton.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
String usuario = usuariol.getText();
|
||
|
String contrasena = String.valueOf(contrasenal.getPassword());
|
||
|
|
||
|
// Realizar la autenticación con la base de datos
|
||
|
User user = DatabaseManager.getAuthenticatedUser(usuario, contrasena);
|
||
|
|
||
|
if (user != null) {
|
||
|
JOptionPane.showMessageDialog(null, "Inicio de sesión exitoso");
|
||
|
// Aquí puedes realizar otras acciones después de iniciar sesión correctamente
|
||
|
} else {
|
||
|
JOptionPane.showMessageDialog(null, "Usuario o contraseña incorrectos");
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
SwingUtilities.invokeLater(() -> {
|
||
|
JFrame frame = new JFrame("Login");
|
||
|
frame.setContentPane(new ventana1().panel);
|
||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
frame.pack();
|
||
|
frame.setVisible(true);
|
||
|
});
|
||
|
}
|
||
|
}
|