You are on page 1of 6

UNIVERSIDAD NACIONAL DE

INGENIERÍA
“Año del Fortalecimiento de la Soberanía Nacional”

Informe Práctica Calificada 4


Curso: Programación orientada a objetos ( BMA15-O)
Facultad: FIEE-UNI
Docente: Ing. Castillo Belsuzarri, Trini Sandro
Integrantes:
● Huamán Cárdenas, Dalí Elías Vicente 11
● Frias Rojas, Ariel Amado 8
● Silva Valenzuela, Julio Cesar 22

2022
Creación de un sistema de login y usuario
package proyecto02;

import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;

public class login extends javax.swing.JFrame {


Conexion cx;

public login() {
initComponents();
this.setTitle("LOGIN");
this.setSize(500,500);
Image img=Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/
login.png"));
lblLogo.setIcon(new
ImageIcon(img.getScaledInstance(lblLogo.getWidth(),lblLogo.getHeight(),Image.SCALE_SM
OOTH)));
this.setIconImage(img);
this.setLocationRelativeTo(null);
cx=new Conexion("cecytem");
cx.conectar();
}

/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

Usuario = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
btnIniciar = new javax.swing.JButton();
Cancelar = new javax.swing.JButton();
lblLogo = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

Usuario.setText("Usuario");

jLabel2.setText("Password");
jTextField1.setText("jTextField1");

jTextField2.setText("jTextField1");

btnIniciar.setText("Iniciar");
btnIniciar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnIniciarActionPerformed(evt);
}
});

Cancelar.setText("Cancelar");
Cancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CancelarActionPerformed(evt);
}
});

lblLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/login.png")));
// NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)
.addGroup(layout.createSequentialGroup()
.addComponent(btnIniciar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Cancelar))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(43, 43, 43)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
179, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(Usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 63,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING, false)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE,
179, Short.MAX_VALUE)
.addComponent(lblLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
Short.MAX_VALUE))))
.addContainerGap(80, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(lblLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 139,
Short.MAX_VALUE)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(Usuario)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(btnIniciar)
.addComponent(Cancelar))
.addGap(39, 39, 39))
);

pack();
}// </editor-fold>

private void btnIniciarActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {


String user=txtUsuario.getText();
String password=String.valueOf(txtPassword.getPassword());
String query="SELECT * FROM usuario WHERE user='"+user+"' and
password'"+password+"'";
Statement st=cx.conectar().createStatement;

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* 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(login.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVER
E, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton Cancelar;
private javax.swing.JLabel Usuario;
private javax.swing.JButton btnIniciar;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JLabel lblLogo;
// End of variables declaration
}

You might also like