pkgAgenda_Virtual.frmVerContactos.java Source code

Java tutorial

Introduction

Here is the source code for pkgAgenda_Virtual.frmVerContactos.java

Source

/*
 * 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 pkgAgenda_Virtual;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.Timer;

/**
 *
 * @author Carlos
 */
public class frmVerContactos extends javax.swing.JInternalFrame {

    /**
     * Creates new form frmAgregarContacto
     */
    public frmVerContactos() {
        initComponents();
        ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
        this.setLocation(500, 100);
        timerVerContacto.start();
        cargarcontactos();
    }

    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnModificar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblContactos = new javax.swing.JTable();
        pnlInfo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        btnEliminar = new javax.swing.JButton();
        lblImagenContacto = new javax.swing.JLabel();
        lblNombreContacto = new javax.swing.JLabel();
        lblSexoContact = new javax.swing.JLabel();
        lblFecNacContact = new javax.swing.JLabel();
        lblCorreoContact = new javax.swing.JLabel();
        lblTel1Contacto = new javax.swing.JLabel();
        lblTel2Contact = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        btnGenerarReporte = new javax.swing.JButton();
        mbnAgregarActs = new javax.swing.JMenuBar() {
            public void paintComponent(Graphics g) {
                g.drawImage(Toolkit.getDefaultToolkit()
                        .getImage(getClass().getResource("/pkgAgenda_Virtual/Images/Toolbar.png")), 0, 0, this);
            }
        };
        jMenu2 = new javax.swing.JMenu();
        mnuMinMax = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnModificar.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        btnModificar
                .setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkgAgenda_Virtual/Images/Editar.png"))); // NOI18N
        btnModificar.setText("Modificar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        getContentPane().add(btnModificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 540, -1, -1));

        tblContactos.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        tblContactos.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null }, { null, null }, { null, null } },
                new String[] { "Title 1", "Title 2" }));
        tblContactos.setTableHeader(null);
        tblContactos.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tblContactosFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(tblContactos);
        if (tblContactos.getColumnModel().getColumnCount() > 0) {
            tblContactos.getColumnModel().getColumn(0).setMinWidth(50);
            tblContactos.getColumnModel().getColumn(0).setPreferredWidth(50);
            tblContactos.getColumnModel().getColumn(0).setMaxWidth(50);
        }

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 241, 460));

        pnlInfo.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel1.setText("Haga clic en cualquier contacto para ");

        jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel2.setText("ver su informacion completa.");

        javax.swing.GroupLayout pnlInfoLayout = new javax.swing.GroupLayout(pnlInfo);
        pnlInfo.setLayout(pnlInfoLayout);
        pnlInfoLayout.setHorizontalGroup(pnlInfoLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlInfoLayout.createSequentialGroup().addContainerGap()
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2).addComponent(jLabel1))
                        .addContainerGap(172, Short.MAX_VALUE)));
        pnlInfoLayout.setVerticalGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        pnlInfoLayout.createSequentialGroup().addContainerGap(439, Short.MAX_VALUE)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2).addContainerGap()));

        getContentPane().add(pnlInfo, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 20, 410, 500));

        txtBuscar.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        txtBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtBuscarKeyTyped(evt);
            }
        });
        getContentPane().add(txtBuscar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 17, 241, -1));

        btnEliminar.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        btnEliminar.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/pkgAgenda_Virtual/Images/Cancelar.png"))); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        getContentPane().add(btnEliminar, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 540, -1, -1));

        lblImagenContacto.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/pkgAgenda_Virtual/Images/Contacto.png"))); // NOI18N
        getContentPane().add(lblImagenContacto, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 20, -1, -1));

        lblNombreContacto.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        lblNombreContacto.setText("Nombre Apellido");
        getContentPane().add(lblNombreContacto, new org.netbeans.lib.awtextra.AbsoluteConstraints(384, 27, -1, -1));

        lblSexoContact.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
        lblSexoContact.setText("Hombrujer");
        getContentPane().add(lblSexoContact, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 127, -1, -1));

        lblFecNacContact.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
        lblFecNacContact.setText("1996/09/26");
        getContentPane().add(lblFecNacContact, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 167, -1, -1));

        lblCorreoContact.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
        lblCorreoContact.setText("nickname@server.com");
        getContentPane().add(lblCorreoContact, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 207, -1, -1));

        lblTel1Contacto.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
        lblTel1Contacto.setText("7777-7777");
        getContentPane().add(lblTel1Contacto, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 247, -1, -1));

        lblTel2Contact.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
        lblTel2Contact.setText("2222-2222");
        getContentPane().add(lblTel2Contact, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 287, -1, -1));

        jLabel7.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jLabel7.setText("Sexo:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(426, 127, -1, -1));

        jLabel8.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jLabel8.setText("Fecha de Nacimiento:");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(314, 167, -1, -1));

        jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jLabel9.setText("Correo:");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(411, 207, -1, -1));

        jLabel10.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jLabel10.setText("Telefono 1:");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(386, 247, -1, -1));

        jLabel11.setFont(new java.awt.Font("Segoe UI", 0, 16)); // NOI18N
        jLabel11.setText("Telefono 2:");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(386, 287, -1, -1));

        btnGenerarReporte.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        btnGenerarReporte.setText("Generar reporte de Contactos");
        btnGenerarReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarReporteActionPerformed(evt);
            }
        });
        getContentPane().add(btnGenerarReporte,
                new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 540, -1, -1));

        mbnAgregarActs.setBorder(null);
        mbnAgregarActs.setPreferredSize(new Dimension(486, 24));
        mbnAgregarActs.setMinimumSize(new Dimension(486, 24));
        mbnAgregarActs.setMaximumSize(new Dimension(486, 24));
        mbnAgregarActs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mbnAgregarActsMousePressed(evt);
            }
        });
        mbnAgregarActs.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                mbnAgregarActsMouseDragged(evt);
            }
        });

        jMenu2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkgAgenda_Virtual/Images/Cerrar.png"))); // NOI18N
        jMenu2.addMenuListener(new javax.swing.event.MenuListener() {
            public void menuCanceled(javax.swing.event.MenuEvent evt) {
            }

            public void menuDeselected(javax.swing.event.MenuEvent evt) {
            }

            public void menuSelected(javax.swing.event.MenuEvent evt) {
                jMenu2MenuSelected(evt);
            }
        });
        jMenu2.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
                jMenu2MenuKeyPressed(evt);
            }

            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
            }

            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });
        mbnAgregarActs.add(jMenu2);

        mnuMinMax.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/pkgAgenda_Virtual/Images/Minimizar.png"))); // NOI18N
        mnuMinMax.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnuMinMaxMouseClicked(evt);
            }
        });
        mnuMinMax.addMenuListener(new javax.swing.event.MenuListener() {
            public void menuCanceled(javax.swing.event.MenuEvent evt) {
            }

            public void menuDeselected(javax.swing.event.MenuEvent evt) {
            }

            public void menuSelected(javax.swing.event.MenuEvent evt) {
                mnuMinMaxMenuSelected(evt);
            }
        });
        mnuMinMax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuMinMaxActionPerformed(evt);
            }
        });
        mbnAgregarActs.add(mnuMinMax);

        jMenu3.setBackground(new java.awt.Color(255, 255, 255));
        jMenu3.setText("Ver Contactos");
        jMenu3.setEnabled(false);
        jMenu3.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        mbnAgregarActs.add(jMenu3);

        setJMenuBar(mbnAgregarActs);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    ResultSet rs;
    DefaultListModel nombres = new DefaultListModel();
    DefaultListModel apellidos = new DefaultListModel();
    String[] contactosdesordenados;
    String[] contactosordenados;
    int num_contacto = 0, cantidad_contactos = 0;
    public static Paragraph P;

    public void PDF() throws SQLException {
        Document documento = new Document();
        FileOutputStream FacturaPdf;

        try {
            FacturaPdf = new FileOutputStream("archives/Contactos.pdf");

            PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
            com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
            writer.setBoxSize("art", rct);
            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

        } catch (DocumentException | FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }

        try {
            Calendar fecha = Calendar.getInstance();
            documento.open();
            com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
            imagen.setAbsolutePosition(0f, 0f);
            documento.add(imagen);
            Paragraph AV = new Paragraph("Agenda Virtual",
                    FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
            AV.setAlignment(Element.ALIGN_RIGHT);
            documento.add(AV);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph("Contactos de " + frmLogin.usuario));
            documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                    + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                    + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            PdfPTable tabla = new PdfPTable(4);
            tabla.addCell("Apellidos");
            tabla.addCell("Nombres");
            tabla.addCell("Telefono");
            tabla.addCell("Correo");

            //sdfhfjhsdfsd
            rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
            while (rs.next()) {
                cantidad_contactos += 1;
            }
            contactosdesordenados = new String[cantidad_contactos];
            rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
            while (rs.next()) {
                contactosdesordenados[num_contacto] = H.desencriptar(rs.getString(1));
                num_contacto += 1;
            }
            contactosordenados = new String[cantidad_contactos];
            Arrays.sort(contactosdesordenados);
            contactosordenados = contactosdesordenados;
            for (int i = 0; i < contactosordenados.length; i++) {
                if (!"".equals(contactosordenados[i].toString())) {
                    rs = H.Buscar(
                            "SELECT ape_contacto, nom_contacto, tel1_contacto, correo_contacto FROM Contactos WHERE ape_contacto = '"
                                    + H.encriptar(contactosordenados[i].toString()) + "'");
                    while (rs.next()) {
                        tabla.addCell(H.desencriptar(rs.getString(1)));
                        tabla.addCell(H.desencriptar(rs.getString(2)));
                        tabla.addCell(rs.getString(3));
                        tabla.addCell(H.desencriptar(rs.getString(4)));
                    }
                }
            }

            //askjdhskfjhdf
            documento.add(tabla);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(P);
            documento.close();
        } catch (DocumentException | IOException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }

    }

    static class HeaderFooter extends PdfPageEventHelper {
        private final String encabezado = "Agenda Virtual";
        PdfTemplate total;

        @Override
        public void onOpenDocument(PdfWriter writer, Document document) {
            total = writer.getDirectContent().createTemplate(30, 16);
            String Pagina = String.format("Pagina " + writer.getPageNumber());
            P = new Paragraph(Pagina);
            P.setAlignment(Element.ALIGN_RIGHT);
        }
    }

    public void cargarcontactos() {
        try {
            rs = H.Buscar("SELECT nom_contacto, ape_contacto, foto_contacto FROM Contactos WHERE cod_usu = "
                    + H.Usuario + "");
            Object[] fila = new Object[2];
            H.modelimagen.addColumn("Foto");
            H.modelimagen.addColumn("Nombre");
            while (rs.next()) {
                ImageIcon imagen = new ImageIcon(rs.getString(3));
                ImageIcon foto = new ImageIcon(imagen.getImage().getScaledInstance(52, 62, 0));
                fila[0] = foto;
                nombres.addElement(rs.getString(1));
                apellidos.addElement(rs.getString(2));
                fila[1] = H.desencriptar(rs.getString(1)) + " " + H.desencriptar(rs.getString(2));
                H.modelimagen.addRow(fila);
            }
            tblContactos.setModel(H.modelimagen);
            if (tblContactos.getColumnModel().getColumnCount() > 0) {
                tblContactos.getColumnModel().getColumn(0).setMinWidth(50);
                tblContactos.getColumnModel().getColumn(0).setPreferredWidth(50);
                tblContactos.getColumnModel().getColumn(0).setMaxWidth(50);
            }
            tblContactos.setRowHeight(65);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }
    }

    Helper H = new Helper();
    public static int tbl = -1;

    Timer timerVerContacto = new Timer(1, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (H.frmVerContacto == 2) {
                try {
                    frmVerContactos.this.setIcon(false);
                } catch (PropertyVetoException ex) {
                    Logger.getLogger(frmNotas.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (tbl == 1) {
                H.LimpiarTabla(tblContactos);
                cargarcontactos();
                tbl = 0;
            }
        }
    });

    private void jMenu2MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenu2MenuSelected
        this.dispose();
        frmAgenda.vercontacto = 0;
        timerVerContacto.stop();
    }//GEN-LAST:event_jMenu2MenuSelected

    private void jMenu2MenuKeyPressed(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_jMenu2MenuKeyPressed

    }//GEN-LAST:event_jMenu2MenuKeyPressed

    private void mnuMinMaxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnuMinMaxMouseClicked

    }//GEN-LAST:event_mnuMinMaxMouseClicked

    private void mnuMinMaxMenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_mnuMinMaxMenuSelected
        try {
            H.frmVerContacto = 1;
            frmVerContactos.this.setIcon(true);

        } catch (PropertyVetoException ex) {
            Logger.getLogger(frmNotas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_mnuMinMaxMenuSelected

    private void mnuMinMaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuMinMaxActionPerformed

    }//GEN-LAST:event_mnuMinMaxActionPerformed

    int pX, pY;

    private void mbnAgregarActsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mbnAgregarActsMousePressed
        pX = evt.getX();
        pY = evt.getY();
    }//GEN-LAST:event_mbnAgregarActsMousePressed

    private void mbnAgregarActsMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mbnAgregarActsMouseDragged
        setLocation(getLocation().x + evt.getX() - pX, getLocation().y + evt.getY() - pY);
    }//GEN-LAST:event_mbnAgregarActsMouseDragged

    public static String nombremod, apellidomod;

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        if (tblContactos.getSelectedRow() > -1) {
            int fila = tblContactos.getSelectedRow();
            nombremod = nombres.getElementAt(fila).toString();
            apellidomod = apellidos.getElementAt(fila).toString();
            frmModificarContactos mod = new frmModificarContactos(null, closable);
            mod.setVisible(true);
        } else {
        }
    }//GEN-LAST:event_btnModificarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed

        if (tblContactos.getSelectedRow() > -1) {
            try {
                int fila = tblContactos.getSelectedRow();
                String nombre, apellido, foto = "";
                nombre = nombres.getElementAt(fila).toString();
                apellido = apellidos.getElementAt(fila).toString();
                rs = H.Buscar("SELECT foto_contacto FROM Contactos WHERE nom_contacto = '" + nombre
                        + "' AND ape_contacto = '" + apellido + "'");
                while (rs.next()) {
                    foto = rs.getString(1);
                }
                File f = new File(foto);
                f.delete();
                H.Eliminar("DELETE FROM Contactos WHERE nom_contacto = '" + nombre + "' AND ape_contacto = '"
                        + apellido + "'");
                H.LimpiarTabla(tblContactos);
                cargarcontactos();
                pnlInfo.setVisible(true);
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex.toString());
            }
        } else {
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void tblContactosFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tblContactosFocusGained
        pnlInfo.setVisible(false);
        try {
            int fila = tblContactos.getSelectedRow();
            String nombre, apellido;
            nombre = nombres.getElementAt(fila).toString();
            apellido = apellidos.getElementAt(fila).toString();
            rs = H.Buscar(
                    "SELECT nom_contacto, ape_contacto, sex_contacto, fecnac_contacto, correo_contacto, foto_contacto, tel1_contacto, tel2_contacto FROM Contactos WHERE nom_contacto = '"
                            + nombre + "' AND ape_contacto = '" + apellido + "'");

            while (rs.next()) {
                String nom, ape, sex, fecnac, correo, tel1, tel2;
                nom = H.desencriptar(rs.getString(1));
                ape = H.desencriptar(rs.getString(2));
                sex = H.desencriptar(rs.getString(3));
                fecnac = rs.getString(4);
                correo = H.desencriptar(rs.getString(5));
                tel1 = rs.getString(7);
                tel2 = rs.getString(8);
                lblNombreContacto.setText(nom + " " + ape);
                lblSexoContact.setText(sex);
                lblFecNacContact.setText(fecnac);
                lblCorreoContact.setText(correo);
                lblTel1Contacto.setText(tel1);
                lblTel2Contact.setText(tel2);
                ImageIcon imagen = new ImageIcon(rs.getString(6));
                Image img = imagen.getImage().getScaledInstance(lblImagenContacto.getWidth(),
                        lblImagenContacto.getHeight(), Image.SCALE_SMOOTH);
                Icon icono = new ImageIcon(img);
                lblImagenContacto.setIcon(icono);
            }
            btnModificar.requestFocusInWindow();

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }
    }//GEN-LAST:event_tblContactosFocusGained

    private void txtBuscarKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBuscarKeyTyped
        try {
            rs = H.Buscar("SELECT nom_contacto, ape_contacto, foto_contacto FROM Contactos WHERE cod_usu = "
                    + H.Usuario + " AND nom_contacto LIKE '%" + H.encriptar(txtBuscar.getText()) + "%'");
            H.LimpiarTabla(tblContactos);
            nombres.clear();
            apellidos.clear();
            Object[] fila = new Object[2];
            H.modelimagen.addColumn("Foto");
            H.modelimagen.addColumn("Nombre");
            while (rs.next()) {
                ImageIcon imagen = new ImageIcon(rs.getString(3));
                ImageIcon foto = new ImageIcon(imagen.getImage().getScaledInstance(52, 62, 0));
                fila[0] = foto;
                nombres.addElement(rs.getString(1));
                apellidos.addElement(rs.getString(2));
                fila[1] = H.desencriptar(rs.getString(1)) + " " + H.desencriptar(rs.getString(2));
                H.modelimagen.addRow(fila);
            }
            tblContactos.setModel(H.modelimagen);
            if (tblContactos.getColumnModel().getColumnCount() > 0) {
                tblContactos.getColumnModel().getColumn(0).setMinWidth(50);
                tblContactos.getColumnModel().getColumn(0).setPreferredWidth(50);
                tblContactos.getColumnModel().getColumn(0).setMaxWidth(50);
            }
            tblContactos.setRowHeight(65);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }
    }//GEN-LAST:event_txtBuscarKeyTyped

    private void btnGenerarReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarReporteActionPerformed
        try {
            PDF();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "archives\\Contactos.pdf");
        } catch (SQLException | IOException ex) {
            Logger.getLogger(frmVerContactos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnGenerarReporteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGenerarReporte;
    private javax.swing.JButton btnModificar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCorreoContact;
    private javax.swing.JLabel lblFecNacContact;
    private javax.swing.JLabel lblImagenContacto;
    private javax.swing.JLabel lblNombreContacto;
    private javax.swing.JLabel lblSexoContact;
    private javax.swing.JLabel lblTel1Contacto;
    private javax.swing.JLabel lblTel2Contact;
    private javax.swing.JMenuBar mbnAgregarActs;
    private javax.swing.JMenu mnuMinMax;
    private javax.swing.JPanel pnlInfo;
    private javax.swing.JTable tblContactos;
    private javax.swing.JTextField txtBuscar;
    // End of variables declaration//GEN-END:variables
}