package pacman;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;
import javax.swing.border.BevelBorder;
import javax.swing.JPasswordField;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.UIManager;
import javax.swing.ImageIcon;
import java.awt.SystemColor;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField textID;
private JLabel lblNewLabel_1;
private JButton btnIniciarS;
private JButton btnReg;
private JLabel lblNewLabel_2;
private JButton btnSalir;
private JLabel lblNewLabel_3;
private Home ventanaHome;
private JPasswordField textPass;
private BaseDatos bd = null;
private ResultSet rs = null;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setUndecorated(true);
frame.setLocationRelativeTo(frame);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
/* Instancia la Base de Datos */
bd = new BaseDatos();
setIconImage(Toolkit.getDefaultToolkit().getImage(Login.class.getResource("/Imagenes/p6.png")));
setTitle("Juego");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 553, 351);
//contentPane = new JPanel();
contentPane = new Fondo("/Imagenes/p2.jpg");
contentPane.setBorder(new BevelBorder(BevelBorder.LOWERED, new Color(255, 255, 255), new Color(255, 255, 255), new Color(255, 255, 255), new Color(255, 255, 255)));
contentPane.setBackground(Color.BLACK);
contentPane.setForeground(new Color(255, 255, 255));
setContentPane(contentPane);
contentPane.setLayout(null);
textID = new JTextField();
textID.setHorizontalAlignment(SwingConstants.LEFT);
textID.setForeground(Color.DARK_GRAY);
textID.setBackground(Color.WHITE);
textID.setToolTipText("");
textID.setText("\r\n");
textID.setBounds(200, 99, 233, 26);
contentPane.add(textID);
textID.setColumns(10);
JLabel lblNewLabel = new JLabel("Usuario");
lblNewLabel.setBackground(SystemColor.text);
lblNewLabel.setForeground(SystemColor.text);
lblNewLabel.setFont(new Font("Consolas", Font.BOLD, 19));
lblNewLabel.setBounds(63, 95, 97, 26);
contentPane.add(lblNewLabel);
lblNewLabel_1 = new JLabel("Contrase�a");
lblNewLabel_1.setBackground(Color.WHITE);
lblNewLabel_1.setForeground(SystemColor.text);
lblNewLabel_1.setFont(new Font("Consolas", Font.BOLD, 19));
lblNewLabel_1.setBounds(63, 152, 109, 26);
contentPane.add(lblNewLabel_1);
btnIniciarS = new JButton("Iniciar Sesi�n");
btnIniciarS.setForeground(Color.WHITE);
btnIniciarS.setBackground(Color.DARK_GRAY);
btnIniciarS.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*String id = textID.getText().trim();
String passwd = new String(textPass.getPassword());
if (id.isEmpty() || passwd.isEmpty())
JOptionPane.showMessageDialog(null, "Usuario/Contrase�a son nulos","ERROR", JOptionPane.ERROR_MESSAGE);
else{
if (id.equals("admin")){
if (bd.validaLoginUser(id, passwd)){
lblNewLabel_3.setVisible(false); */
crearVentana();
/* }
else{
lblNewLabel_3.setText("Credenciales Incorrectas");
lblNewLabel_3.setVisible(true);
}
}
else{
lblNewLabel_3.setText("Solo el User ADMIN puede Ingresar");
lblNewLabel_3.setVisible(true);
}
}*/
}
});
btnIniciarS.setBounds(200, 211, 122, 23);
contentPane.add(btnIniciarS);
btnReg = new JButton("Registrarse");
btnReg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = textID.getText().trim();
String passwd = new String(textPass.getPassword());
if (id.isEmpty() || passwd.isEmpty())
JOptionPane.showMessageDialog(null, "Usuario/Contrase�a son nulos","ERROR", JOptionPane.ERROR_MESSAGE);
else{
if (bd.validaRegistracion(id)){
lblNewLabel_3.setText("El Usuario Ingresado Ya Existe");
lblNewLabel_3.setVisible(true);
}
else{
bd.registrarse(id,passwd);
JOptionPane.showMessageDialog(null, "Se Genero el Usuario con Exito","Informacion", JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
btnReg.setForeground(Color.WHITE);
btnReg.setBackground(Color.DARK_GRAY);
btnReg.setBounds(332, 211, 101, 23);
contentPane.add(btnReg);
lblNewLabel_2 = new JLabel("Bienvenido al Pac-Man");
lblNewLabel_2.setForeground(new Color(255, 215, 0));
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2.setVerticalAlignment(SwingConstants.TOP);
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblNewLabel_2.setBounds(125, 27, 357, 26);
contentPane.add(lblNewLabel_2);
btnSalir = new JButton("Salir");
btnSalir.setForeground(Color.RED);
btnSalir.setBackground(Color.BLACK);
btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
abreDialogoSalida();
}
});
btnSalir.setBounds(438, 279, 89, 23);
contentPane.add(btnSalir);
lblNewLabel_3 = new JLabel("Usuario/Contrase�a Incorrecto");
lblNewLabel_3.setForeground(new Color(255, 69, 0));
lblNewLabel_3.setBounds(200, 283, 228, 14);
lblNewLabel_3.setVisible(false);
contentPane.add(lblNewLabel_3);
textPass = new JPasswordField();
textPass.setBounds(200, 156, 236, 27);
contentPane.add(textPass);
JLabel lblNewLabel_4 = new JLabel("New label");
lblNewLabel_4.setIcon(new ImageIcon(Login.class.getResource("/Imagenes/picon.png")));
lblNewLabel_4.setBounds(407, 32, 33, 19);
contentPane.add(lblNewLabel_4);
JLabel lversion = new JLabel("V 1.10");
lversion.setFont(new Font("Tahoma", Font.PLAIN, 9));
lversion.setForeground(SystemColor.windowBorder);
lversion.setBounds(494, 313, 33, 14);
contentPane.add(lversion);
}
void abreDialogoSalida(){
int res = JOptionPane.showConfirmDialog(this, "Desea Salir ? ","Salida",JOptionPane.YES_NO_OPTION);
if (res==JOptionPane.YES_NO_OPTION)
System.exit(0);
}
public void crearVentana(){
ventanaHome= new Home(this);
//ventanaHome.setUndecorated(true);
ventanaHome.setLocationRelativeTo(ventanaHome);
ventanaHome.setVisible(true);
this.setVisible(false);
}
public String getUser(){
return textID.getText();
}
}
No hay comentarios:
Publicar un comentario