Al trabajar como freelance me acople a los horarios de la empresa, ya que tenia que estar ahi para checar el proceso de como se trabaja dentro de la empresa, habia momentos que los libros de java me generaban mas dudas que respuestas, ya que java aunque no habia vuelto a trabajar con el decidi retomarlo ya que era mas flexible, a mi parecer.
Java era o sigue siendo un lenguaje de programacion muy usado. Pero el sistema necesitaba algo visual.
Le habia comentado que usaramos PHP otro lenguaje de programacion web pero no se convencio ya que la persona encargada queria algo visual y con botones.
Login.java
package inicio;
import ConexionBaseDatos.BdConexion;
import ConexionBaseDatos.conectar;
import javax.swing.JOptionPane;
import java.sql.*;
import Menus.MenuDeOpciones;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* @author jektour
*/
public class Login1 extends javax.swing.JFrame {
//String [] Usuario = ["Hmgn", "Miguel", "Hector", "Sergio"];
static String cap;
static String usuarioX;
conectar cc= new conectar();
Connection cn= cc.conexion();
public static String getCap() {
return cap;
}
public static String getUsuarioX() {
return usuarioX;
}
public JPasswordField getTxtPassword() {
return txtPassword;
}
public JTextField getTxtUsuario() {
return txtUsuario;
}
public static void setCap(String cap) {
Login1.cap = cap;
}
public static void setUsuarioX(String usuarioX) {
Login1.usuarioX = usuarioX;
}
public void setTxtPassword(JPasswordField txtPassword) {
this.txtPassword = txtPassword;
}
public void setTxtUsuario(JTextField txtUsuario) {
this.txtUsuario = txtUsuario;
}
/**
* Creates new form Login1
*/
public Login1() {
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")
// //GEN-BEGIN:initComponents
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel25 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtUsuario = new javax.swing.JTextField();
btnAceptar = new javax.swing.JButton();
txtPassword = new javax.swing.JPasswordField();
btnSalir = new javax.swing.JButton();
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setUndecorated(true);
jPanel1.setPreferredSize(new java.awt.Dimension(652, 308));
jLabel25.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N
jLabel25.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel25.setText("AutoLineas MRD S.A. DE CV");
jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N
jLabel1.setText("Bienvenido");
jLabel2.setText("Usuario:");
jLabel3.setText("Password:");
btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});
txtPassword.setToolTipText("");
txtPassword.setVerifyInputWhenFocusTarget(false);
btnSalir.setText("Salir");
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(34, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 511, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(76, 76, 76))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(55, 55, 55)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(150, 150, 150))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(268, 268, 268)
.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(214, 214, 214)
.addComponent(btnAceptar)
.addGap(65, 65, 65)
.addComponent(btnSalir)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel25)
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAceptar)
.addComponent(btnSalir))
.addGap(44, 44, 44))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
);
pack();
}//
//GEN-END:initComponents
private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
String usuario = txtUsuario.getText();
String password = new String(txtPassword.getPassword());
if(("".equals(usuario)) && ("".equals(password))){
JOptionPane.showMessageDialog(null,"No hay datos de entrada en login");
}else{
acceder(usuario, password);
}
}//GEN-LAST:event_btnAceptarActionPerformed
private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
System.exit(0);
}//GEN-LAST:event_btnSalirActionPerformed
public void acceder(String usuario, String password){
String user = usuario;
String pass = password;
String clave = "";
//String cap="";
String nick = "";
String sql="SELECT * FROM usuario WHERE usuario='"+user+"' && password='"+pass+"'";
try{
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
cap= rs.getString("tipousuario");
nick = rs.getString("usuario");
usuarioX = rs.getString("NombreUsuario");
clave = rs.getString("password");
}
if (user.equals(nick) && (pass.equals(clave))){
JOptionPane.showMessageDialog(null,"Bienvenido: " + usuarioX);
this.dispose();
MenuDeOpciones menu = new MenuDeOpciones();
menu.setLocationRelativeTo(null);
menu.setVisible(true);
}else{
JOptionPane.showMessageDialog(null, "Usuario o contraseña incorrecta");
txtUsuario.setText("");
txtPassword.setText("");
}
}catch (Exception e) {
}
}
/**
* @param args the command line arguments
*/
public static void Login(String args[]) {
/* Set the Nimbus look and feel */
//
/* 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(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login1().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnSalir;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel25;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JTextField txtUsuario;
// End of variables declaration//GEN-END:variables
}