2024-03-03 22:08:11 +00:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
public class ventana1 {
|
2024-03-11 04:25:41 +00:00
|
|
|
JPanel panel,panel2;
|
2024-03-03 22:08:11 +00:00
|
|
|
private JTextField usuariol;
|
|
|
|
private JButton iniciarBoton;
|
|
|
|
private JButton registerBoton;
|
|
|
|
private JPasswordField contrasenal;
|
2024-03-11 03:59:19 +00:00
|
|
|
private JPanel panelPrincipal;
|
2024-03-03 22:08:11 +00:00
|
|
|
private JLabel usuarioLabel;
|
|
|
|
private JLabel contrasenaLabel;
|
|
|
|
private JLabel inicioText;
|
2024-03-04 14:47:47 +00:00
|
|
|
private JLabel nombre;
|
2024-03-03 22:08:11 +00:00
|
|
|
|
|
|
|
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
|
2024-03-11 03:59:19 +00:00
|
|
|
// Obtener el JFrame actual y cerrarlo
|
|
|
|
JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(panel);
|
|
|
|
frame.dispose();
|
|
|
|
|
|
|
|
// Mostrar el panel de inicio de sesión
|
|
|
|
JFrame principalFrame = new JFrame("Principal");
|
2024-03-11 04:25:41 +00:00
|
|
|
principalFrame.setContentPane(new ventana2().panelV2);
|
2024-03-11 03:59:19 +00:00
|
|
|
principalFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
principalFrame.pack();
|
|
|
|
principalFrame.setVisible(true);
|
2024-03-03 22:08:11 +00:00
|
|
|
} else {
|
|
|
|
JOptionPane.showMessageDialog(null, "Usuario o contraseña incorrectos");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-04 14:47:47 +00:00
|
|
|
registerBoton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
// Cerrar el JFrame actual (ventana1)
|
|
|
|
JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(panel);
|
|
|
|
frame.dispose();
|
|
|
|
|
|
|
|
// Abrir la ventana de registro
|
|
|
|
JFrame registerFrame = new JFrame("Registro de Usuario");
|
|
|
|
registerFrame.setContentPane(new registerV().getPanel());
|
|
|
|
registerFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
|
registerFrame.pack();
|
|
|
|
registerFrame.setVisible(true);
|
|
|
|
}
|
2024-03-03 22:08:11 +00:00
|
|
|
});
|
|
|
|
}
|
2024-03-04 14:47:47 +00:00
|
|
|
|
|
|
|
|
2024-03-03 22:08:11 +00:00
|
|
|
}
|