pkgAgenda_Virtual.frmActividades.java Source code

Java tutorial

Introduction

Here is the source code for pkgAgenda_Virtual.frmActividades.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.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
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.JOptionPane;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
import static pkgAgenda_Virtual.frmVerContactos.P;

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

    /**
     * Creates new form frmActividades
     */
    public frmActividades() {
        initComponents();
        ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
        timerActs.start();
        tbls();
        timersql.start();
    }

    /**
     * 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblHoy = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblAnteriores = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblProximas = new javax.swing.JTable();
        btnModificar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnReporte = new javax.swing.JButton();
        btnReporte1 = new javax.swing.JButton();
        mbnActs = 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));
        setClosable(true);
        setIconifiable(true);
        setTitle("Actividades");

        jScrollPane1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        tblHoy.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
        tblHoy.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null }, { null, null, null } },
                new String[] { "Fecha Actividad", "Actividad", "Tipo Actividad" }) {
            boolean[] canEdit = new boolean[] { false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        tblHoy.setGridColor(new java.awt.Color(153, 153, 153));
        tblHoy.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblHoyMouseClicked(evt);
            }
        });
        tblHoy.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tblHoyFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(tblHoy);
        if (tblHoy.getColumnModel().getColumnCount() > 0) {
            tblHoy.getColumnModel().getColumn(0).setResizable(false);
            tblHoy.getColumnModel().getColumn(1).setResizable(false);
            tblHoy.getColumnModel().getColumn(2).setResizable(false);
        }

        jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
        jLabel1.setText("Hoy:");

        jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N
        jLabel2.setText("Anteriores:");

        jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N
        jLabel3.setText("Proximas:");

        jScrollPane2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        tblAnteriores.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
        tblAnteriores.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null }, { null, null, null } },
                new String[] { "Fecha Actividad", "Actividad", "Tipo Actividad" }));
        tblAnteriores.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tblAnterioresFocusGained(evt);
            }
        });
        jScrollPane2.setViewportView(tblAnteriores);
        if (tblAnteriores.getColumnModel().getColumnCount() > 0) {
            tblAnteriores.getColumnModel().getColumn(0).setResizable(false);
            tblAnteriores.getColumnModel().getColumn(1).setResizable(false);
            tblAnteriores.getColumnModel().getColumn(2).setResizable(false);
        }

        jScrollPane3.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        tblProximas.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
        tblProximas.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null }, { null, null, null } },
                new String[] { "Fecha Actividad", "Actividad", "Tipo Actividad" }));
        tblProximas.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tblProximasFocusGained(evt);
            }
        });
        jScrollPane3.setViewportView(tblProximas);
        if (tblProximas.getColumnModel().getColumnCount() > 0) {
            tblProximas.getColumnModel().getColumn(0).setResizable(false);
            tblProximas.getColumnModel().getColumn(1).setResizable(false);
            tblProximas.getColumnModel().getColumn(2).setResizable(false);
        }

        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 Actividad");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });

        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 Actividad");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        btnReporte.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        btnReporte.setText("Generar Reporte de Actividades Personales");
        btnReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReporteActionPerformed(evt);
            }
        });

        btnReporte1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        btnReporte1.setText("Generar Reporte de Actividades de Estudio");
        btnReporte1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReporte1ActionPerformed(evt);
            }
        });

        mbnActs.setBorder(null);
        mbnActs.setPreferredSize(new Dimension(486, 24));
        mbnActs.setMinimumSize(new Dimension(486, 24));
        mbnActs.setMaximumSize(new Dimension(486, 24));
        mbnActs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mbnActsMousePressed(evt);
            }
        });
        mbnActs.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                mbnActsMouseDragged(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) {
            }
        });
        mbnActs.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);
            }
        });
        mbnActs.add(mnuMinMax);

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

        setJMenuBar(mbnActs);

        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()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(0, 172,
                                        Short.MAX_VALUE))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                        Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel2)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 261,
                                        Short.MAX_VALUE)
                                .addComponent(jLabel3).addComponent(jScrollPane3,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnModificar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnReporte, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnReporte1, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap(12, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1).addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 196,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup().addComponent(btnModificar)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnEliminar)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jScrollPane3,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 204,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup().addComponent(btnReporte1)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(btnReporte))))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 444,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

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

    Helper H = new Helper();
    ResultSet rs;

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

        try {
            FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.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("Actividades Personales 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 tblHoy = new PdfPTable(4);
            PdfPTable tblAntes = new PdfPTable(4);
            PdfPTable tblDespues = new PdfPTable(4);
            tblHoy.addCell("Titulo");
            tblHoy.addCell("Fecha");
            tblHoy.addCell("Hora");
            tblHoy.addCell("Lugar");
            tblAntes.addCell("Titulo");
            tblAntes.addCell("Fecha");
            tblAntes.addCell("Hora");
            tblAntes.addCell("Lugar");
            tblDespues.addCell("Titulo");
            tblDespues.addCell("Fecha");
            tblDespues.addCell("Hora");
            tblDespues.addCell("Lugar");

            //sdfhfjhsdfsd
            int valor;

            rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = "
                    + H.Usuario + " AND id_tipoact = 2");
            while (rs.next()) {
                String fecharecibida = rs.getString(2).substring(0, 10);
                valor = H.FechaAnterior(fecharecibida);
                if (valor == 2) {
                    tblHoy.addCell(H.desencriptar(rs.getString(1)));
                    tblHoy.addCell(fecharecibida);
                    tblHoy.addCell(rs.getString(3).substring(0, 5));
                    tblHoy.addCell(H.desencriptar(rs.getString(4)));
                } else if (valor == 1) {
                    tblAntes.addCell(H.desencriptar(rs.getString(1)));
                    tblAntes.addCell(fecharecibida);
                    tblAntes.addCell(rs.getString(3).substring(0, 5));
                    tblAntes.addCell(H.desencriptar(rs.getString(4)));
                } else if (valor == 0) {
                    tblDespues.addCell(H.desencriptar(rs.getString(1)));
                    tblDespues.addCell(fecharecibida);
                    tblDespues.addCell(rs.getString(3).substring(0, 5));
                    tblDespues.addCell(H.desencriptar(rs.getString(4)));
                }
            }

            //askjdhskfjhdf
            documento.add(new Paragraph("Actividades Pasadas"));
            documento.add(new Paragraph(" "));
            documento.add(tblAntes);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph("Actividades de Hoy"));
            documento.add(new Paragraph(" "));
            documento.add(tblHoy);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph("Actividades Futuras"));
            documento.add(new Paragraph(" "));
            documento.add(tblDespues);
            documento.add(new Paragraph(" "));
            documento.add(P);
            documento.close();
        } catch (DocumentException | IOException ex) {
            JOptionPane.showMessageDialog(null, ex.toString());
        }

    };

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

        try {
            FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.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("Actividades de Estudio 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 tblHoy = new PdfPTable(4);
            PdfPTable tblAntes = new PdfPTable(4);
            PdfPTable tblDespues = new PdfPTable(4);
            tblHoy.addCell("Asignatura");
            tblHoy.addCell("Tarea");
            tblHoy.addCell("Fecha");
            tblHoy.addCell("Hora");
            tblAntes.addCell("Asignatura");
            tblAntes.addCell("Tarea");
            tblAntes.addCell("Fecha");
            tblAntes.addCell("Hora");
            tblDespues.addCell("Asignatura");
            tblDespues.addCell("Tarea");
            tblDespues.addCell("Fecha");
            tblDespues.addCell("Hora");

            //sdfhfjhsdfsd
            int valor;

            rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = "
                    + H.Usuario + " AND id_tipoact = 1");
            while (rs.next()) {
                String fecharecibida = rs.getString(3).substring(0, 10);
                valor = H.FechaAnterior(fecharecibida);
                if (valor == 2) {
                    tblHoy.addCell(H.desencriptar(rs.getString(1)));
                    tblHoy.addCell(H.desencriptar(rs.getString(2)));
                    tblHoy.addCell(fecharecibida);
                    tblHoy.addCell(rs.getString(4).substring(0, 5));
                } else if (valor == 1) {
                    tblAntes.addCell(H.desencriptar(rs.getString(1)));
                    tblAntes.addCell(H.desencriptar(rs.getString(2)));
                    tblAntes.addCell(fecharecibida);
                    tblAntes.addCell(rs.getString(4).substring(0, 5));
                } else if (valor == 0) {
                    tblDespues.addCell(H.desencriptar(rs.getString(1)));
                    tblDespues.addCell(H.desencriptar(rs.getString(2)));
                    tblDespues.addCell(fecharecibida);
                    tblDespues.addCell(rs.getString(4).substring(0, 5));
                }
            }

            //askjdhskfjhdf
            documento.add(new Paragraph("Actividades Pasadas"));
            documento.add(new Paragraph(" "));
            documento.add(tblAntes);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph("Actividades de Hoy"));
            documento.add(new Paragraph(" "));
            documento.add(tblHoy);
            documento.add(new Paragraph(" "));
            documento.add(new Paragraph("Actividades Futuras"));
            documento.add(new Paragraph(" "));
            documento.add(tblDespues);
            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 static int sql = 0;

    Timer timerActs = new Timer(1, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (H.frmActividades == 2) {
                try {
                    frmActividades.this.setIcon(false);
                } catch (PropertyVetoException ex) {
                    Logger.getLogger(frmNotas.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

    Timer timersql = new Timer(1, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (sql == 1) {
                tbls();
                sql = 0;
            }
        }
    });

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        int val = -1;
        if (tblHoy.getSelectedRow() != val) {
            val = tblHoy.getSelectedRow();
            H.nom_act = H.encriptar(tblHoy.getValueAt(val, 1).toString());
            frmModificarActividades mod = new frmModificarActividades(null, closable);
            mod.setVisible(true);
        } else if (tblAnteriores.getSelectedRow() != val) {
            val = tblAnteriores.getSelectedRow();
            H.nom_act = H.encriptar(tblAnteriores.getValueAt(val, 1).toString());
            frmModificarActividades mod = new frmModificarActividades(null, closable);
            mod.setVisible(true);
        } else if (tblProximas.getSelectedRow() != val) {
            val = tblProximas.getSelectedRow();
            H.nom_act = H.encriptar(tblProximas.getValueAt(val, 1).toString());
            frmModificarActividades mod = new frmModificarActividades(null, closable);
            mod.setVisible(true);
        }

    }//GEN-LAST:event_btnModificarActionPerformed

    private void jMenu2MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenu2MenuSelected
        this.dispose();
        frmAgenda.acts = 0;
        timerActs.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.frmActividades = 1;
            frmActividades.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 mbnActsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mbnActsMousePressed
        pX = evt.getX();
        pY = evt.getY();
    }//GEN-LAST:event_mbnActsMousePressed

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

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

    }//GEN-LAST:event_tblHoyMouseClicked

    private void tblHoyFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tblHoyFocusGained
        tblAnteriores.clearSelection();
        tblProximas.clearSelection();
    }//GEN-LAST:event_tblHoyFocusGained

    private void tblAnterioresFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tblAnterioresFocusGained
        tblHoy.clearSelection();
        tblProximas.clearSelection();
    }//GEN-LAST:event_tblAnterioresFocusGained

    private void tblProximasFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tblProximasFocusGained
        tblHoy.clearSelection();
        tblAnteriores.clearSelection();
    }//GEN-LAST:event_tblProximasFocusGained

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        int val = -1;
        if (tblHoy.getSelectedRow() != val) {
            val = tblHoy.getSelectedRow();
            H.nom_act = H.encriptar(tblHoy.getValueAt(val, 1).toString());
        } else if (tblAnteriores.getSelectedRow() != val) {
            val = tblAnteriores.getSelectedRow();
            H.nom_act = H.encriptar(tblAnteriores.getValueAt(val, 1).toString());
        } else if (tblProximas.getSelectedRow() != val) {
            val = tblProximas.getSelectedRow();
            H.nom_act = H.encriptar(tblProximas.getValueAt(val, 1).toString());
        }

        H.Eliminar("DELETE FROM Actividades WHERE nom_act = '" + H.nom_act + "'");
        tbls();
    }//GEN-LAST:event_btnEliminarActionPerformed

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

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

    private void tbls() {
        H.Cleantbl(tblHoy, tblAnteriores, tblProximas);
        DefaultTableModel modelhoy = new DefaultTableModel();
        modelhoy = H.BuscarTbl(
                "SELECT act.fecha_act, act.nom_act, tipact.nom_tipoact FROM Actividades AS act, Tipo_Actividades AS tipact WHERE act.cod_usu = '"
                        + H.Usuario + "' AND act.id_tipoact = tipact.id_tipoact");
        tblHoy.setModel(modelhoy);
        tblAnteriores.setModel(H.modelantes);
        tblProximas.setModel(H.modeldespues);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnModificar;
    private javax.swing.JButton btnReporte;
    private javax.swing.JButton btnReporte1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JMenuBar mbnActs;
    private javax.swing.JMenu mnuMinMax;
    private javax.swing.JTable tblAnteriores;
    private javax.swing.JTable tblHoy;
    private javax.swing.JTable tblProximas;
    // End of variables declaration//GEN-END:variables
}