Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.67 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package guardarhuellas;
  7.  
  8. import com.digitalpersona.onetouch.DPFPDataPurpose;
  9. import com.digitalpersona.onetouch.DPFPFeatureSet;
  10. import com.digitalpersona.onetouch.DPFPGlobal;
  11. import com.digitalpersona.onetouch.DPFPSample;
  12. import com.digitalpersona.onetouch.DPFPTemplate;
  13. import com.digitalpersona.onetouch.capture.DPFPCapture;
  14. import com.digitalpersona.onetouch.capture.event.DPFPDataAdapter;
  15. import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
  16. import com.digitalpersona.onetouch.capture.event.DPFPErrorAdapter;
  17. import com.digitalpersona.onetouch.capture.event.DPFPErrorEvent;
  18. import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
  19. import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
  20. import com.digitalpersona.onetouch.capture.event.DPFPSensorAdapter;
  21. import com.digitalpersona.onetouch.capture.event.DPFPSensorEvent;
  22. import com.digitalpersona.onetouch.processing.DPFPEnrollment;
  23. import com.digitalpersona.onetouch.processing.DPFPFeatureExtraction;
  24. import com.digitalpersona.onetouch.processing.DPFPImageQualityException;
  25. import java.awt.Image;
  26. import java.io.ByteArrayInputStream;
  27. import java.lang.reflect.InvocationTargetException;
  28. import java.sql.Connection;
  29. import java.sql.PreparedStatement;
  30. import java.sql.SQLException;
  31. import javax.swing.ImageIcon;
  32. import javax.swing.JOptionPane;
  33. import javax.swing.SwingUtilities;
  34.  
  35.  
  36. /**
  37. *
  38. * @author MATHEO
  39. */
  40. public class applet extends javax.swing.JApplet {
  41.  
  42. /**
  43. * Initializes the applet NewJApplet
  44. */
  45. @Override
  46. public void init() {
  47. /* Set the Nimbus look and feel */
  48. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  49. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  50. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  51. */
  52. try {
  53. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  54. if ("Nimbus".equals(info.getName())) {
  55. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  56. break;
  57. }
  58. }
  59. } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
  60. java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  61. }
  62. //</editor-fold>
  63. //</editor-fold>
  64.  
  65. //</editor-fold>
  66. //</editor-fold>
  67. //</editor-fold>
  68. //</editor-fold>
  69.  
  70. //</editor-fold>
  71. //</editor-fold>
  72.  
  73.  
  74. /* Create and display the applet */
  75. try {
  76. java.awt.EventQueue.invokeAndWait(() -> {
  77. initComponents();
  78. setSize(407, 502);
  79.  
  80. iniciar();
  81. comenzar();
  82. estadohuella();
  83. btnguardar.setEnabled(false);
  84. btncancel.grabFocus();
  85. });
  86. } catch (InterruptedException | InvocationTargetException ex) {
  87. }
  88. }
  89.  
  90. /**
  91. * This method is called from within the init() method to initialize the
  92. * form. WARNING: Do NOT modify this code. The content of this method is
  93. * always regenerated by the Form Editor.
  94. */
  95. @SuppressWarnings("unchecked")
  96. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  97. private void initComponents() {
  98.  
  99. panel1 = new javax.swing.JPanel();
  100. imgenhuella = new javax.swing.JLabel();
  101. panel2 = new javax.swing.JPanel();
  102. jScrollPane1 = new javax.swing.JScrollPane();
  103. txtarea = new javax.swing.JTextArea();
  104. btncancel = new javax.swing.JButton();
  105. btnguardar = new javax.swing.JButton();
  106.  
  107. getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  108.  
  109. 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
  110. panel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  111.  
  112. imgenhuella.setBackground(new java.awt.Color(204, 204, 204));
  113. panel1.add(imgenhuella, new org.netbeans.lib.awtextra.AbsoluteConstraints(47, 28, 310, 180));
  114.  
  115. getContentPane().add(panel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 410, 240));
  116.  
  117. panel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  118.  
  119. txtarea.setColumns(20);
  120. txtarea.setRows(5);
  121. jScrollPane1.setViewportView(txtarea);
  122.  
  123. panel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 20, 400, 110));
  124.  
  125. btncancel.setText("Cancelar");
  126. btncancel.addActionListener(new java.awt.event.ActionListener() {
  127. public void actionPerformed(java.awt.event.ActionEvent evt) {
  128. btncancelActionPerformed(evt);
  129. }
  130. });
  131. panel2.add(btncancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 160, 150, 50));
  132.  
  133. btnguardar.setText("Guardar");
  134. btnguardar.addActionListener(new java.awt.event.ActionListener() {
  135. public void actionPerformed(java.awt.event.ActionEvent evt) {
  136. btnguardarActionPerformed(evt);
  137. }
  138. });
  139. panel2.add(btnguardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 160, 150, 50));
  140.  
  141. getContentPane().add(panel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 240, 410, 260));
  142. }// </editor-fold>
  143.  
  144. private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {
  145. // TODO add your handling code here:
  146.  
  147. guardarhuella();
  148. reclutador.clear();
  149. imgenhuella.setIcon(null);
  150. comenzar();
  151.  
  152. }
  153.  
  154. private void btncancelActionPerformed(java.awt.event.ActionEvent evt) {
  155. // TODO add your handling code here:
  156. System.exit(0);
  157. }
  158.  
  159. private final DPFPCapture lector = DPFPGlobal.getCaptureFactory().createCapture();
  160. private final DPFPEnrollment reclutador = DPFPGlobal.getEnrollmentFactory().createEnrollment();
  161. private DPFPTemplate template;
  162. public static String TEMPLATS_PROPERTY = "template";
  163.  
  164. public void iniciar(){
  165. lector.addDataListener(new DPFPDataAdapter(){
  166. @Override public void dataAcquired (final DPFPDataEvent e){
  167.  
  168. SwingUtilities.invokeLater(() -> {
  169. EnviarTexto("La Huella Digital ha sido Capturada");
  170. ProcesarCaptura(e.getSample());
  171. });
  172. }});
  173. lector.addReaderStatusListener(new DPFPReaderStatusAdapter(){
  174. @Override public void readerConnected(final DPFPReaderStatusEvent e){
  175. SwingUtilities.invokeLater(() -> {
  176. EnviarTexto("El huellero digtal esta conectado o Activado ");
  177. });}
  178. @Override public void readerDisconnected(final DPFPReaderStatusEvent e){
  179. SwingUtilities.invokeLater(() -> {
  180. EnviarTexto("El huellero digital esta Desconectado o Desactivado ");
  181. });
  182. }});
  183.  
  184. lector.addSensorListener(new DPFPSensorAdapter(){
  185. public void fingerToched(final DPFPSensorEvent e){
  186. SwingUtilities.invokeLater(() -> {
  187. EnviarTexto("El dedo se ha ubicado en el huellero ");
  188. });}
  189. @Override public void fingerGone(final DPFPSensorEvent e){
  190. SwingUtilities.invokeLater(() -> {
  191. EnviarTexto("El dedo se ha quitado del huellero ");
  192. });}
  193. });
  194.  
  195. lector.addErrorListener(new DPFPErrorAdapter(){
  196. public void error(final DPFPErrorEvent e){
  197. SwingUtilities.invokeLater(() -> {
  198. EnviarTexto("Error "+e.getError());
  199. });}
  200. });}
  201.  
  202. public DPFPFeatureSet Featuresinscriopcion;
  203. public DPFPFeatureSet Featureverificaion;
  204. public DPFPFeatureSet extraerCaracteristica(DPFPSample samble, DPFPDataPurpose purpose){
  205.  
  206. DPFPFeatureExtraction Extractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction();
  207.  
  208. try{
  209. return Extractor.createFeatureSet(samble,purpose);
  210. } catch (DPFPImageQualityException e){
  211. return null;
  212. }
  213. }
  214. public Image crearhuella(DPFPSample sample){
  215.  
  216. return DPFPGlobal.getSampleConversionFactory().createImage(sample);
  217. }
  218. public void dibujarhuella(Image image){
  219. imgenhuella.setIcon(new ImageIcon(
  220. image.getScaledInstance(imgenhuella.getWidth(),imgenhuella.getHeight(),Image.SCALE_DEFAULT)));
  221. repaint();
  222. }
  223.  
  224. public void estadohuella(){
  225. EnviarTexto("Muestras de huellas necesarias para guardarla "+reclutador.getFeaturesNeeded());
  226. }
  227. public void EnviarTexto(String string){
  228. txtarea.append(string+"n");
  229. }
  230. public void comenzar(){
  231. lector.startCapture();
  232. EnviarTexto("utlizando el lector de huellas");
  233. }
  234.  
  235. public void parar(){
  236. lector.stopCapture();
  237. EnviarTexto("no se esta utlizando el lector");
  238. }
  239.  
  240. public DPFPTemplate getTemplate(){
  241. return template;
  242. }
  243. public void setTemplate(DPFPTemplate template){
  244. DPFPTemplate old = this.template;
  245. this.template = template;
  246. firePropertyChange(TEMPLATS_PROPERTY, old, template);
  247. }
  248.  
  249. public void ProcesarCaptura(DPFPSample sample){
  250. Featuresinscriopcion = extraerCaracteristica(sample, DPFPDataPurpose.DATA_PURPOSE_ENROLLMENT);
  251. Featureverificaion = extraerCaracteristica(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION);
  252.  
  253.  
  254.  
  255. if(Featuresinscriopcion != null)
  256.  
  257. try {
  258. System.out.println("las caracteristica de la huella han sido creadas");
  259. reclutador.addFeatures(Featuresinscriopcion);
  260.  
  261. Image image = crearhuella(sample);
  262. dibujarhuella(image);
  263.  
  264.  
  265.  
  266. } catch (DPFPImageQualityException ex) {
  267. System.out.println("error "+ex.getMessage());
  268. }
  269.  
  270. finally{
  271. estadohuella();
  272. switch(reclutador.getTemplateStatus()){
  273. case TEMPLATE_STATUS_READY:
  274. parar();
  275. setTemplate(reclutador.getTemplate());
  276. EnviarTexto("la huella ha sido creada");
  277. btnguardar.setEnabled(true);
  278. btnguardar.grabFocus();
  279. break;
  280.  
  281. case TEMPLATE_STATUS_FAILED:
  282. parar();
  283. estadohuella();
  284. setTemplate(null);
  285. JOptionPane.showMessageDialog(null,"la huella no ha sido registrada intente nuevamente");
  286. start();
  287. break;
  288. }
  289.  
  290. }
  291. }
  292. guardarhuellas.conection cn=new guardarhuellas.conection();
  293.  
  294. public void guardarhuella(){
  295. ByteArrayInputStream datohuella= new ByteArrayInputStream(template.serialize());
  296. Integer tamanohuella=template.serialize().length;
  297.  
  298. String nombre = JOptionPane.showInputDialog("Nombre");
  299. try {
  300. Connection c=cn.conectar();
  301. try (PreparedStatement guardarStmt = c.prepareStatement("INSERT INTO somehue(id,nombre,huella) values(null,?,?)")) {
  302. guardarStmt.setString(1, nombre);
  303. guardarStmt.setBinaryStream(2, datohuella,tamanohuella);
  304. //ejecuta la sentencia
  305. guardarStmt.execute();
  306. }
  307. JOptionPane.showMessageDialog(null,"Huella guardada correctamente");
  308. cn.desconectar();
  309. btnguardar.setEnabled(false);
  310.  
  311.  
  312. } catch (SQLException e) {
  313. System.out.println("Error al guardar la huella"+e.getMessage());
  314. }finally{
  315. cn.desconectar();
  316. }
  317. }
  318.  
  319. // Variables declaration - do not modify
  320. private javax.swing.JButton btncancel;
  321. private javax.swing.JButton btnguardar;
  322. private javax.swing.JLabel imgenhuella;
  323. private javax.swing.JScrollPane jScrollPane1;
  324. private javax.swing.JPanel panel1;
  325. private javax.swing.JPanel panel2;
  326. private javax.swing.JTextArea txtarea;
  327. // End of variables declaration
  328. }
  329.  
  330. y este es el de conecion de la BD
  331.  
  332. /*
  333. * To change this license header, choose License Headers in Project Properties.
  334. * To change this template file, choose Tools | Templates
  335. * and open the template in the editor.
  336. */
  337. package guardarhuellas;
  338.  
  339. import java.sql.Connection;
  340. import java.sql.DriverManager;
  341. import java.sql.SQLException;
  342. import javax.swing.JOptionPane;
  343. /**
  344. *
  345. * @author MATHEO
  346. */
  347. public class conection {
  348. Connection conn=null;
  349.  
  350. public Connection conectar(){
  351. try {
  352.  
  353. Class.forName("com.mysql.jdbc.Driver");
  354. conn = DriverManager.getConnection("jdbc:mysql://localhost/bd_huelladi", "root", "");
  355. if(conn!=null ){
  356. System.out.println("se conecto a la base de datos ");
  357. }else if (conn==null){
  358. throw new SQLException();
  359. }
  360. } catch (SQLException e) {
  361. JOptionPane.showMessageDialog(null,e.getMessage());
  362. }catch (ClassNotFoundException e){
  363. JOptionPane.showMessageDialog(null,"se produjo siguente error: "+e.getMessage());
  364. }catch (NullPointerException e){
  365. JOptionPane.showMessageDialog(null,"se produjo el siguiente error: "+e.getMessage());
  366. }
  367. finally{
  368. return conn;
  369. }
  370.  
  371. }
  372.  
  373. public void desconectar(){
  374. conn=null;
  375. System.out.println("se desconecto la base de datos");
  376. }
  377. }
  378.  
  379. <!DOCTYPE html>
  380. <!--
  381. To change this license header, choose License Headers in Project Properties.
  382. To change this template file, choose Tools | Templates
  383. and open the template in the editor.
  384. -->
  385. <html>
  386. <head>
  387. <title>Bienvenidos</title>
  388. <meta charset="UTF-8">
  389. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  390. </head>
  391. <body>
  392. <h1>Mi primer applet creado para leer la huella ojala lo ahaga jajajajjajaj</h1>
  393. <applet
  394. CODEBASE = "."
  395. CODE = "guardarhuellas.applet.class"
  396. ARCHIVE = "guardarhuellas.jar"
  397. WIDTH = 407
  398. HEIGHT = 502
  399.  
  400. ></applet>
  401. </body>
  402. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement