Huella Digital
Huella Digital
Huella Digital
java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package procedimientos;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
com.griaule.grfingerjava.FingerprintImage;
com.griaule.grfingerjava.IFingerEventListener;
com.griaule.grfingerjava.IImageEventListener;
com.griaule.grfingerjava.IStatusEventListener;
com.griaule.grfingerjava.GrFingerJava;
com.griaule.grfingerjava.GrFingerJavaException;
java.io.File;
com.griaule.grfingerjava.MatchingContext;
com.griaule.grfingerjava.Template;
interfaz.PantallaPrincipal;
java.io.ByteArrayInputStream;
java.sql.*;
javax.swing.*;
java.sql.ResultSet;
try {
fingerprintSDK = new MatchingContext();
//Inicializa la captura de huella digital.
GrFingerJava.initializeCapture(this);
} catch (Exception e) {
//Si ocurre un error se cierra la aplicacin.
e.printStackTrace();
System.exit(1);
}
}
/**
* Este mtodo es llamado cada vez que la imagen de una huella ha sido capturada.
*/
/**
* Inicializa la conexin a la base de datos y prepara las operaciones para inserta
r,
* eliminar y modificar los datos
*/
private void initDB() {
try {
//Carga el driver ODBC
Class.forName(com.mysql.jdbc.Driver);
//Se conecta a la bd
dbConnection = DriverManager.getConnection(jdbc:mysql://172.17.17.152:3306/biomet
ria,biometria, b10m3tr14.);
Statement stm = dbConnection.createStatement();
//Prepara las consultas/sentencias que se utilizarn
//guardarStmt = dbConnection.prepareStatement(INSERT INTO huellas(id, nombres, hu
ella1) values(?,?,?));
guardarStmt = dbConnection.prepareStatement(INSERT INTO huella(cedula,nombres,hue
lla1,huella2) values(?,?,?,?));
guardarStmt2 = dbConnection.prepareStatement(INSERT INTO huella(huella2) values(?
));
identificarStmt = dbConnection.prepareStatement(SELECT nombres, huella1 FROM huel
la);
verificarStmt = dbConnection.prepareStatement(SELECT nombres FROM huella WHERE hu
ella1=?);
verificarCedula = dbConnection.prepareStatement(SELECT id FROM huellas WHERE id=?)
;
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Cierra la conexin a la base de datos y libera los recursos empleados.
*/
private void destroyDB() {
try {
//Se cierran todas las sentencias
guardarStmt.close();
identificarStmt.close();
//Cierra la conexin a la base
dbConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Extrae la plantilla de la imagen de la huella actual.
*/
public void extract() {
try {
//Extrae la plantilla de la imagen.
template = fingerprintSDK.extract(fingerprint);
//Muestra la plantilla en la imagen
ui.showImage(GrFingerJava.getBiometricImage(template,fingerprint));
} catch (GrFingerJavaException e) {
e.printStackTrace();
}
}
/*
* Guarda los datos de la huella digital actual en la base de datos
*/
public void guardarHuella(){
//Obtiene los datos del template de la huella actual
fingerprintData = new ByteArrayInputStream(template.getData());
fingerprintDataLength = template.getData().length;
fingerprintData2 = new ByteArrayInputStream(template.getData());
fingerprintDataLength2 = template.getData().length;
//Pregunta la identificacion y el nombre de la persona a la cual corresponde dic
ha huella
String cedula = JOptionPane.showInputDialog(Cedula:);
String nombre = JOptionPane.showInputDialog(Nombre:);
int ident = Integer.parseInt(cedula);
try {
//Establece los valores para la sentencia SQL
guardarStmt.setInt(1, ident);
guardarStmt.setString(2,nombre);
guardarStmt.setBinaryStream(3, fingerprintData, fingerprintDataLength);
guardarStmt.setBinaryStream(4, fingerprintData2, fingerprintDataLength);
//Ejecuta la sentencia
guardarStmt.execute();
JOptionPane.showMessageDialog(ui, Datos ingresados correctamente);
} catch (SQLException ex) {
//Si ocurre un error lo indica en la consola
System.err.println(Error al guardar los datos de la huella.);
ex.printStackTrace();
}
}
/**
* Verifica la huella digital actual contra otra en la base de datos
*/
public void verify(String nom) {
try {
return;
}
}
JOptionPane.showMessageDialog(ui, Usuario no autorizado. Debe estar registrado pa
ra poder tener accoso a la aplicacion);
}
catch (SQLException e) {
e.printStackTrace();
} catch (GrFingerJavaException e) {
e.printStackTrace();
}
}
}
Clase PantallaPrincipal.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PantallaPrincipal.java
*
* Created on 3/11/2011, 10:03:44 AM
*/
package interfaz;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import procedimientos.Util;
import javax.swing.UIManager;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.*;
import java.io.File;
import javax.swing.GroupLayout.ParallelGroup;
/**
*
* @author NAPSTER2011
*/
public class PantallaPrincipal extends JApplet {
//objeto usado para realizar todas las operaciones relacionadas al Fingerprint-S
DK
private Util procedimientosSDK;
//Panel para mostrar la huella digital
private JPanel fingerprintViewPanel = null;
private JPanel fingerprintViewPanel2 = null;
//Imagen de la huella actual
private BufferedImage fingerprintImage = null;
private BufferedImage fingerprintImage2 = null;
/* Crea una nueva forma de PantallaPrincipal */
public PantallaPrincipal() {
inicializar();
//initComponents();
/*Inicializa la captura de huellas*/
procedimientosSDK.inicializarCaptura();
/*centra la ventana en la pantalla*/
//setLocationRelativeTo(null);
/*hace visible la ventana*/
setVisible(true);
}
@Override
public void init() {
String grFingerNativeDirectory = new File(.).getAbsolutePath();
Util.setFingerprintSDKNativeDirectory(grFingerNativeDirectory);
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
//setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName(PantallaPrincipal); // NOI18N
/*addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});*/
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Huella 1, jav
ax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP));
jPanel1.setName(panelContenedor); // NOI18N
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Acciones, jav
ax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP));
jButton2.setText(Guardar);
jButton2.setName(btnGuardar); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText(Identificar);
jButton3.setName(btnIdentificar); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING, false)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupL
ayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing
.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING, false)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALU
E))
.addGap(38, 38, 38))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jButton2)
//.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short
.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jButton3))
.addGap(22, 22, 22))
));
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(31, 31, 31)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.
GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(156, 156, 156)
.addComponent(jPanel2, 0, 247, Short.MAX_VALUE)
.addGap(172, 172, 172))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.Group
Layout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.Gr
oupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
)));
jPanel1.getAccessibleContext().setAccessibleName(null);
//pack();
}
/** This method is called from within the constructor to
.addComponent(jButton3))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.
GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.Group
Layout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.Group
Layout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.
GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1.getAccessibleContext().setAccessibleName(null);
}// </editor-fold>//GEN-END:initComponents
*/
private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:ev
ent_formWindowActivated
// TODO add your handling code here:
this.jPanel1.add(crearPanelHuella());
}//GEN-LAST:event_formWindowActivated
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
T:event_jButton2ActionPerformed
// TODO add your handling code here:
procedimientosSDK.guardarHuella();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
T:event_jButton3ActionPerformed
// TODO add your handling code here:
procedimientosSDK.identificarPersona();
}//GEN-LAST:event_jButton3ActionPerformed
/**
* Mtodo utilizado para mostrar la imagen de la huella
* en el panel correspondiente.
*/
public void showImage(BufferedImage image) {
//Utiliza el imageProducer para crear una imagen de la huella digital
fingerprintImage = image;
fingerprintImage2 = image;
//Se dibuja la nueva imagen
repaint();
}
/**
* @param args the command line arguments
*/
/*public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInsta
lledLookAndFeels()) {
if (Nimbus.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PantallaPrincipal.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PantallaPrincipal.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PantallaPrincipal.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PantallaPrincipal.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PantallaPrincipal().setVisible(true);
}
});
}*/
/**
* Se establece el estilo visual de la aplicacin y se realiza la inicializacin de l
a clase
* que contiene los procedimientos principales.
**/
public void inicializar() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.err.println(No se pudo aplicar el estilo visual);
}
//Crea una instancia de Util
this.procedimientosSDK = new Util(this);
}
/**
* Crea el panel que contendr la imagen de la huella digital
*/
private JComponent crearPanelHuella() {
//Crea un panel nuevo para mostrar la huella
fingerprintViewPanel = new JPanel(){
}
}
};
//Se agrega un borde alrededor del panel
fingerprintViewPanel2.setBorder(new CompoundBorder (
new EmptyBorder (2,2,2,2),
new BevelBorder(BevelBorder.LOWERED)));
//si no hay existe el panel de la huella no devuelve nada
if(fingerprintViewPanel2==null)
{
return null;
}else{ // de lo contrario devuelve el panel mismo
return fingerprintViewPanel2;
}
}
// Variables declaration do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
// End of variables declaration//GEN-END:variables
}
Clase LectorHuella.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lectorhuella;
import interfaz.PantallaPrincipal;
import java.io.File;
import procedimientos.Util;
import java.util.*;
/**
*
* @author NAPSTER2011
*/
public class LectorHuella {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String grFingerNativeDirectory = new File(.).getAbsolutePath();
Util.setFingerprintSDKNativeDirectory(grFingerNativeDirectory);
PantallaPrincipal p = new PantallaPrincipal();
}
}