Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package guardarhuellas;
- import com.digitalpersona.onetouch.DPFPDataPurpose;
- import com.digitalpersona.onetouch.DPFPFeatureSet;
- import com.digitalpersona.onetouch.DPFPGlobal;
- import com.digitalpersona.onetouch.DPFPSample;
- import com.digitalpersona.onetouch.DPFPTemplate;
- import com.digitalpersona.onetouch.capture.DPFPCapture;
- import com.digitalpersona.onetouch.capture.event.DPFPDataAdapter;
- import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
- import com.digitalpersona.onetouch.capture.event.DPFPErrorAdapter;
- import com.digitalpersona.onetouch.capture.event.DPFPErrorEvent;
- import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
- import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
- import com.digitalpersona.onetouch.capture.event.DPFPSensorAdapter;
- import com.digitalpersona.onetouch.capture.event.DPFPSensorEvent;
- import com.digitalpersona.onetouch.processing.DPFPEnrollment;
- import com.digitalpersona.onetouch.processing.DPFPFeatureExtraction;
- import com.digitalpersona.onetouch.processing.DPFPImageQualityException;
- import java.awt.Image;
- import java.io.ByteArrayInputStream;
- import java.lang.reflect.InvocationTargetException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import javax.swing.ImageIcon;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- /**
- *
- * @author MATHEO
- */
- public class applet extends javax.swing.JApplet {
- /**
- * Initializes the applet NewJApplet
- */
- @Override
- public void init() {
- /* 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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- //</editor-fold>
- /* Create and display the applet */
- try {
- java.awt.EventQueue.invokeAndWait(() -> {
- initComponents();
- setSize(407, 502);
- iniciar();
- comenzar();
- estadohuella();
- btnguardar.setEnabled(false);
- btncancel.grabFocus();
- });
- } catch (InterruptedException | InvocationTargetException ex) {
- }
- }
- /**
- * This method is called from within the init() method 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() {
- panel1 = new javax.swing.JPanel();
- imgenhuella = new javax.swing.JLabel();
- panel2 = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- txtarea = new javax.swing.JTextArea();
- btncancel = new javax.swing.JButton();
- btnguardar = new javax.swing.JButton();
- getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- panel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Huella", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Century Schoolbook", 0, 12))); // NOI18N
- panel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- imgenhuella.setBackground(new java.awt.Color(204, 204, 204));
- panel1.add(imgenhuella, new org.netbeans.lib.awtextra.AbsoluteConstraints(47, 28, 310, 180));
- getContentPane().add(panel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 410, 240));
- panel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- txtarea.setColumns(20);
- txtarea.setRows(5);
- jScrollPane1.setViewportView(txtarea);
- panel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 20, 400, 110));
- btncancel.setText("Cancelar");
- btncancel.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btncancelActionPerformed(evt);
- }
- });
- panel2.add(btncancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 160, 150, 50));
- btnguardar.setText("Guardar");
- btnguardar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnguardarActionPerformed(evt);
- }
- });
- panel2.add(btnguardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 160, 150, 50));
- getContentPane().add(panel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 240, 410, 260));
- }// </editor-fold>
- private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- guardarhuella();
- reclutador.clear();
- imgenhuella.setIcon(null);
- comenzar();
- }
- private void btncancelActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(0);
- }
- private final DPFPCapture lector = DPFPGlobal.getCaptureFactory().createCapture();
- private final DPFPEnrollment reclutador = DPFPGlobal.getEnrollmentFactory().createEnrollment();
- private DPFPTemplate template;
- public static String TEMPLATS_PROPERTY = "template";
- public void iniciar(){
- lector.addDataListener(new DPFPDataAdapter(){
- @Override public void dataAcquired (final DPFPDataEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("La Huella Digital ha sido Capturada");
- ProcesarCaptura(e.getSample());
- });
- }});
- lector.addReaderStatusListener(new DPFPReaderStatusAdapter(){
- @Override public void readerConnected(final DPFPReaderStatusEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("El huellero digtal esta conectado o Activado ");
- });}
- @Override public void readerDisconnected(final DPFPReaderStatusEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("El huellero digital esta Desconectado o Desactivado ");
- });
- }});
- lector.addSensorListener(new DPFPSensorAdapter(){
- public void fingerToched(final DPFPSensorEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("El dedo se ha ubicado en el huellero ");
- });}
- @Override public void fingerGone(final DPFPSensorEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("El dedo se ha quitado del huellero ");
- });}
- });
- lector.addErrorListener(new DPFPErrorAdapter(){
- public void error(final DPFPErrorEvent e){
- SwingUtilities.invokeLater(() -> {
- EnviarTexto("Error "+e.getError());
- });}
- });}
- public DPFPFeatureSet Featuresinscriopcion;
- public DPFPFeatureSet Featureverificaion;
- public DPFPFeatureSet extraerCaracteristica(DPFPSample samble, DPFPDataPurpose purpose){
- DPFPFeatureExtraction Extractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction();
- try{
- return Extractor.createFeatureSet(samble,purpose);
- } catch (DPFPImageQualityException e){
- return null;
- }
- }
- public Image crearhuella(DPFPSample sample){
- return DPFPGlobal.getSampleConversionFactory().createImage(sample);
- }
- public void dibujarhuella(Image image){
- imgenhuella.setIcon(new ImageIcon(
- image.getScaledInstance(imgenhuella.getWidth(),imgenhuella.getHeight(),Image.SCALE_DEFAULT)));
- repaint();
- }
- public void estadohuella(){
- EnviarTexto("Muestras de huellas necesarias para guardarla "+reclutador.getFeaturesNeeded());
- }
- public void EnviarTexto(String string){
- txtarea.append(string+"n");
- }
- public void comenzar(){
- lector.startCapture();
- EnviarTexto("utlizando el lector de huellas");
- }
- public void parar(){
- lector.stopCapture();
- EnviarTexto("no se esta utlizando el lector");
- }
- public DPFPTemplate getTemplate(){
- return template;
- }
- public void setTemplate(DPFPTemplate template){
- DPFPTemplate old = this.template;
- this.template = template;
- firePropertyChange(TEMPLATS_PROPERTY, old, template);
- }
- public void ProcesarCaptura(DPFPSample sample){
- Featuresinscriopcion = extraerCaracteristica(sample, DPFPDataPurpose.DATA_PURPOSE_ENROLLMENT);
- Featureverificaion = extraerCaracteristica(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION);
- if(Featuresinscriopcion != null)
- try {
- System.out.println("las caracteristica de la huella han sido creadas");
- reclutador.addFeatures(Featuresinscriopcion);
- Image image = crearhuella(sample);
- dibujarhuella(image);
- } catch (DPFPImageQualityException ex) {
- System.out.println("error "+ex.getMessage());
- }
- finally{
- estadohuella();
- switch(reclutador.getTemplateStatus()){
- case TEMPLATE_STATUS_READY:
- parar();
- setTemplate(reclutador.getTemplate());
- EnviarTexto("la huella ha sido creada");
- btnguardar.setEnabled(true);
- btnguardar.grabFocus();
- break;
- case TEMPLATE_STATUS_FAILED:
- parar();
- estadohuella();
- setTemplate(null);
- JOptionPane.showMessageDialog(null,"la huella no ha sido registrada intente nuevamente");
- start();
- break;
- }
- }
- }
- guardarhuellas.conection cn=new guardarhuellas.conection();
- public void guardarhuella(){
- ByteArrayInputStream datohuella= new ByteArrayInputStream(template.serialize());
- Integer tamanohuella=template.serialize().length;
- String nombre = JOptionPane.showInputDialog("Nombre");
- try {
- Connection c=cn.conectar();
- try (PreparedStatement guardarStmt = c.prepareStatement("INSERT INTO somehue(id,nombre,huella) values(null,?,?)")) {
- guardarStmt.setString(1, nombre);
- guardarStmt.setBinaryStream(2, datohuella,tamanohuella);
- //ejecuta la sentencia
- guardarStmt.execute();
- }
- JOptionPane.showMessageDialog(null,"Huella guardada correctamente");
- cn.desconectar();
- btnguardar.setEnabled(false);
- } catch (SQLException e) {
- System.out.println("Error al guardar la huella"+e.getMessage());
- }finally{
- cn.desconectar();
- }
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btncancel;
- private javax.swing.JButton btnguardar;
- private javax.swing.JLabel imgenhuella;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JPanel panel1;
- private javax.swing.JPanel panel2;
- private javax.swing.JTextArea txtarea;
- // End of variables declaration
- }
- y este es el de conecion de la BD
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package guardarhuellas;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author MATHEO
- */
- public class conection {
- Connection conn=null;
- public Connection conectar(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/bd_huelladi", "root", "");
- if(conn!=null ){
- System.out.println("se conecto a la base de datos ");
- }else if (conn==null){
- throw new SQLException();
- }
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(null,e.getMessage());
- }catch (ClassNotFoundException e){
- JOptionPane.showMessageDialog(null,"se produjo siguente error: "+e.getMessage());
- }catch (NullPointerException e){
- JOptionPane.showMessageDialog(null,"se produjo el siguiente error: "+e.getMessage());
- }
- finally{
- return conn;
- }
- }
- public void desconectar(){
- conn=null;
- System.out.println("se desconecto la base de datos");
- }
- }
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <title>Bienvenidos</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <h1>Mi primer applet creado para leer la huella ojala lo ahaga jajajajjajaj</h1>
- <applet
- CODEBASE = "."
- CODE = "guardarhuellas.applet.class"
- ARCHIVE = "guardarhuellas.jar"
- WIDTH = 407
- HEIGHT = 502
- ></applet>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement