Java tutorial
/* * 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 cachitodelivery; import modelos.Render; import Excepciones.DataAccessException; import Ventana_clases.Fondo_estadisticas; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.ImageIcon; import modelos.Usuario; import java.sql.SQLException; import java.text.ParseException; import java.util.Calendar; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import modelos.Estadistica; import modelos.Fecha; import modelos.Header; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.chart.ChartFactory; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; /** * * @author Cusipuma */ public class Estadisticas extends javax.swing.JFrame implements Runnable { Usuario cuentaOficial = new Usuario(); Principal vent = null; Fecha fecha = new Fecha(); Render r = new Render(); Thread h1; public Estadisticas(Usuario user) throws SQLException { initComponents(); h1 = new Thread(this); h1.start(); colorHeader(3); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); Fondo_estadisticas fondo = new Fondo_estadisticas(1000, 559); add(fondo, BorderLayout.CENTER); cuentaOficial = user; JL_Usuario_admin1.setText("USUARIO: " + cuentaOficial.getApellido() + " " + cuentaOficial.getNombre()); } public void mostrar(boolean b) { setIconImage(new ImageIcon(getClass().getResource("/Ventanas/Icono.png")).getImage()); setSize(1000, 582); setResizable(false); setLocationRelativeTo(null); setTitle("Estadisticas"); setVisible(b); } public void colorHeader(int j) { Header h = new Header(new Color(53, 95, 123), new Color(255, 255, 255)); for (int i = 0; i < j; i++) { jTable1.getColumnModel().getColumn(i).setHeaderRenderer(h); } } /** * 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() { jScrollPane2 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); JL_Usuario_admin1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); JL_Foto_empleado = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); JL_Fecha_Admin1 = new javax.swing.JLabel(); JL_Hora_Admin1 = new javax.swing.JLabel(); jButton7 = new javax.swing.JButton(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jDateChooser1 = new com.toedter.calendar.JDateChooser(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jDateChooser2 = new com.toedter.calendar.JDateChooser(); jComboBox1 = new javax.swing.JComboBox<>(); jTable2.setModel( new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane2.setViewportView(jTable2); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); JL_Usuario_admin1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N JL_Usuario_admin1.setForeground(new java.awt.Color(255, 255, 255)); JL_Usuario_admin1.setText("USUARIO: "); JL_Fecha_Admin1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N JL_Fecha_Admin1.setForeground(new java.awt.Color(255, 255, 255)); JL_Fecha_Admin1.setText("FF/FF/FFFF"); JL_Hora_Admin1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N JL_Hora_Admin1.setForeground(new java.awt.Color(255, 255, 255)); JL_Hora_Admin1.setText("HH:HH"); jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Atras2.png"))); // NOI18N jButton7.setBorder(null); jButton7.setBorderPainted(false); jButton7.setContentAreaFilled(false); jButton7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton7.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Atras2_hover.png"))); // NOI18N jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cadetes_E.png"))); // NOI18N jButton2.setBorder(null); jButton2.setBorderPainted(false); jButton2.setContentAreaFilled(false); jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cadetes_E_hover.png"))); // NOI18N jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Comidas_E.png"))); // NOI18N jButton3.setBorder(null); jButton3.setBorderPainted(false); jButton3.setContentAreaFilled(false); jButton3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton3.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Comidas_E_hover.png"))); // NOI18N jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Meses_E.png"))); // NOI18N jButton4.setBorder(null); jButton4.setBorderPainted(false); jButton4.setContentAreaFilled(false); jButton4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton4.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Meses_E_hover.png"))); // NOI18N jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Zonas_E.png"))); // NOI18N jButton5.setBorder(null); jButton5.setBorderPainted(false); jButton5.setContentAreaFilled(false); jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton5.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Zonas_E_hover.png"))); // NOI18N jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 311, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 296, Short.MAX_VALUE)); jTable1 = new javax.swing.JTable() { public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } }; jTable1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "PORC.", "COD.", "INFORMACION PERTINENTE" }) { boolean[] canEdit = new boolean[] { false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jTable1.setRowHeight(20); jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jTable1.getTableHeader().setResizingAllowed(false); jTable1.getTableHeader().setReorderingAllowed(false); jScrollPane1.setViewportView(jTable1); if (jTable1.getColumnModel().getColumnCount() > 0) { jTable1.getColumnModel().getColumn(0).setResizable(false); jTable1.getColumnModel().getColumn(1).setResizable(false); jTable1.getColumnModel().getColumn(2).setResizable(false); } jDateChooser1.setForeground(new java.awt.Color(53, 95, 123)); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel7.setForeground(new java.awt.Color(53, 95, 123)); jLabel7.setText("DESDE"); jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel8.setForeground(new java.awt.Color(53, 95, 123)); jLabel8.setText("HASTA"); jDateChooser2.setForeground(new java.awt.Color(53, 95, 123)); jComboBox1.setForeground(new java.awt.Color(53, 95, 123)); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "5", "10", "15" })); 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().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jButton2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addComponent(jLabel7) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel8) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 859, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addGap(37, 37, 37) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton7).addGap(70, 70, 70) .addComponent(JL_Foto_empleado, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(133, 133, 133)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(JL_Usuario_admin1, javax.swing.GroupLayout.PREFERRED_SIZE, 897, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addComponent(JL_Fecha_Admin1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 775, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(JL_Hora_Admin1)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(14, 14, 14))) .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup( layout.createSequentialGroup().addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 921, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(JL_Usuario_admin1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2) .addComponent(jButton3) .addComponent(jButton4) .addComponent(jButton5) .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout .createSequentialGroup() .addGap(11, 11, 11) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createSequentialGroup() .addComponent( jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(159, 159, 159) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( JL_Foto_empleado, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(0, 0, Short.MAX_VALUE)))) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING)) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(JL_Hora_Admin1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(JL_Fecha_Admin1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))) .addGap(444, 444, 444))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed try { this.h1.stop(); Principal vent = new Principal(); vent.MenuAdminVisible(true, cuentaOficial); this.dispose(); } catch (DataAccessException ex) { Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton7ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed try { if (jDateChooser1.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } if (jDateChooser2.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } jPanel2.removeAll(); jPanel2.repaint(); ChartPanel panel; JFreeChart chart = null; DefaultCategoryDataset barra = new DefaultCategoryDataset(); Estadistica est = new Estadistica(); String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.YEAR); String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.YEAR); Object[][] cosas; cosas = est.cadete(min, (jComboBox1.getSelectedIndex() + 1) * 5, max); if (cosas[0][0].toString().equals("CHINITO")) { JOptionPane.showMessageDialog(rootPane, "No se encontraron pedidos realizados\nen ese rango de fecha", "Sin pedidos", JOptionPane.ERROR_MESSAGE); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "PORC.", "COD.", "APELLIDOS", "NOMBRES" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(125); jTable1.getColumnModel().getColumn(3).setPreferredWidth(125); colorHeader(4); return; } for (int i = 0; i < cosas.length; i++) { barra.addValue(Integer.parseInt(cosas[i][2].toString()), "Pedidos no entregados", cosas[i][0].toString()); barra.addValue(Integer.parseInt(cosas[i][1].toString()), "Pedidos realizados", cosas[i][0].toString()); } chart = ChartFactory.createBarChart("CADETES CON MAS PEDIDOS", "Cadetes", "Pedidos", barra, PlotOrientation.HORIZONTAL, true, true, true); Object[][] tabla = new Object[cosas.length][4]; float[] porce = est.porcentaje(cosas, 1); for (int i = 0; i < tabla.length; i++) { tabla[i][0] = porce[i]; tabla[i][1] = cosas[i][0]; tabla[i][2] = cosas[i][3]; tabla[i][3] = cosas[i][4]; } jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla, new String[] { "PORC.", "COD.", "APELLIDOS", "NOMBRES" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(125); jTable1.getColumnModel().getColumn(3).setPreferredWidth(125); CategoryPlot plot = (CategoryPlot) chart.getPlot(); panel = new ChartPanel(chart); panel.setBounds(0, 0, 311, 296); jPanel2.add(panel); jPanel2.repaint(); colorHeader(4); } catch (ClassNotFoundException | SQLException | DataAccessException | ParseException ex) { Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try { if (jDateChooser1.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } if (jDateChooser2.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } jPanel2.removeAll(); jPanel2.repaint(); ChartPanel panel; JFreeChart chart = null; DefaultCategoryDataset barra = new DefaultCategoryDataset(); Estadistica est = new Estadistica(); String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.YEAR); String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.YEAR); Object[][] cosas; cosas = est.comidas(min, (jComboBox1.getSelectedIndex() + 1) * 5, max); if (cosas[0][0].toString().equals("CHINITO")) { JOptionPane.showMessageDialog(rootPane, "No se encontraron comidas vendidas\nen ese rango de fecha", "Sin comidas", JOptionPane.ERROR_MESSAGE); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "PORC.", "COD.", "DESCRIPCION", "CANTIDAD" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); jTable1.getColumnModel().getColumn(3).setPreferredWidth(20); colorHeader(4); return; } for (int i = 0; i < cosas.length; i++) barra.addValue(Integer.parseInt(cosas[i][2].toString()), "Cantidad vendida", cosas[i][0].toString()); chart = ChartFactory.createBarChart("COMIDA MAS VENDIDA", "Comidas", "Ventas", barra, PlotOrientation.HORIZONTAL, true, true, true); Object[][] tabla = new Object[cosas.length][4]; float[] porce = est.porcentaje(cosas, 2); for (int i = 0; i < tabla.length; i++) { tabla[i][0] = porce[i]; tabla[i][1] = cosas[i][0]; tabla[i][2] = cosas[i][1].toString().trim(); tabla[i][3] = cosas[i][2]; } jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla, new String[] { "PORC.", "COD.", "DESCRIPCION", "CANTIDAD" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); jTable1.getColumnModel().getColumn(3).setPreferredWidth(20); CategoryPlot plot = (CategoryPlot) chart.getPlot(); panel = new ChartPanel(chart); panel.setBounds(0, 0, 311, 296); jPanel2.add(panel); jPanel2.repaint(); colorHeader(4); } catch (ClassNotFoundException | SQLException | ParseException ex) { Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try { if (jDateChooser1.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } if (jDateChooser2.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } jPanel2.removeAll(); jPanel2.repaint(); ChartPanel panel; JFreeChart chart = null; DefaultCategoryDataset barra = new DefaultCategoryDataset(); Estadistica est = new Estadistica(); String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.YEAR); String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.YEAR); Object[][] cosas; cosas = est.meses(min, (jComboBox1.getSelectedIndex() + 1) * 5, max); if (cosas[0][0].toString().equals("CHINITO")) { JOptionPane.showMessageDialog(rootPane, "No se encontraron facturas\nen ese rango de fecha", "Sin facturas", JOptionPane.ERROR_MESSAGE); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "PORC.", "PED.", "MES / AO", "IMPORTE TOTAL" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(150); jTable1.getColumnModel().getColumn(3).setPreferredWidth(100); colorHeader(4); return; } for (int i = 0; i < cosas.length; i++) barra.addValue(Float.parseFloat(cosas[i][2].toString()), "Pesos", cosas[i][0].toString()); chart = ChartFactory.createBarChart("FACTURACION MENSUAL", "Mes / ao", "Importe total", barra, PlotOrientation.HORIZONTAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); panel = new ChartPanel(chart); panel.setBounds(0, 0, 311, 296); jPanel2.add(panel); jPanel2.repaint(); Object[][] tabla = new Object[cosas.length][4]; float[] porce = new float[cosas.length]; porce = est.porcentajeF(cosas, 2); for (int i = 0; i < tabla.length; i++) { tabla[i][0] = porce[i]; tabla[i][1] = cosas[i][1]; tabla[i][2] = cosas[i][0]; tabla[i][3] = cosas[i][2]; } jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla, new String[] { "PORC.", "PED.", "MES / AO", "IMPORTE TOTAL" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(150); jTable1.getColumnModel().getColumn(3).setPreferredWidth(100); colorHeader(4); } catch (ClassNotFoundException | SQLException | ParseException ex) { Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton4ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed try { if (jDateChooser1.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } if (jDateChooser2.getCalendar() == null) { JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro", JOptionPane.ERROR_MESSAGE); return; } jPanel2.removeAll(); jPanel2.repaint(); ChartPanel panel; JFreeChart chart = null; DefaultCategoryDataset barra = new DefaultCategoryDataset(); Estadistica est = new Estadistica(); String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.MONTH) + " " + jDateChooser1.getCalendar().get(Calendar.YEAR); String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.MONTH) + " " + jDateChooser2.getCalendar().get(Calendar.YEAR); Object[][] cosas; cosas = est.zonas(min, (jComboBox1.getSelectedIndex() + 1) * 5, max); if (cosas[0][0].toString().equals("CHINITO")) { JOptionPane.showMessageDialog(rootPane, "No se encontraron pedidos realizados\nen ese rango de fecha", "Sin pedidos", JOptionPane.ERROR_MESSAGE); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "PORC.", "COD.", "DESCRIPCION", "PEDIDOS" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); jTable1.getColumnModel().getColumn(3).setPreferredWidth(20); colorHeader(4); return; } for (int i = 0; i < cosas.length; i++) barra.addValue(Integer.parseInt(cosas[i][1].toString()), "Cantidad pedidos", cosas[i][0].toString()); chart = ChartFactory.createBarChart("PEDIDOS POR ZONAS", "Zona", "Pedidos", barra, PlotOrientation.HORIZONTAL, true, true, true); Object[][] tabla = new Object[cosas.length][4]; float[] porce = est.porcentaje(cosas, 1); for (int i = 0; i < tabla.length; i++) { tabla[i][0] = porce[i]; tabla[i][1] = cosas[i][0]; tabla[i][2] = cosas[i][2].toString().trim(); tabla[i][3] = cosas[i][1]; } jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla, new String[] { "PORC.", "COD.", "DESCRIPCION", "PEDIDOS" })); jTable1.getColumnModel().getColumn(0).setPreferredWidth(15); jTable1.getColumnModel().getColumn(1).setPreferredWidth(15); jTable1.getColumnModel().getColumn(2).setPreferredWidth(200); jTable1.getColumnModel().getColumn(3).setPreferredWidth(20); CategoryPlot plot = (CategoryPlot) chart.getPlot(); panel = new ChartPanel(chart); panel.setBounds(0, 0, 311, 296); jPanel2.add(panel); jPanel2.repaint(); colorHeader(4); } catch (ClassNotFoundException | SQLException | ParseException ex) { Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton5ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* 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 ex) { java.util.logging.Logger.getLogger(Estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Estadisticas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // new Listado_empleados().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel JL_Fecha_Admin1; private javax.swing.JLabel JL_Foto_empleado; private javax.swing.JLabel JL_Hora_Admin1; private javax.swing.JLabel JL_Usuario_admin1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton7; private javax.swing.JComboBox<String> jComboBox1; private com.toedter.calendar.JDateChooser jDateChooser1; private com.toedter.calendar.JDateChooser jDateChooser2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable1; private javax.swing.JTable jTable2; // End of variables declaration//GEN-END:variables @Override public void run() { Fecha f = new Fecha(); fecha = f; Thread ct = Thread.currentThread(); while (ct == h1) { JL_Fecha_Admin1.setText(fecha.getFecha()); JL_Hora_Admin1.setText(fecha.getHora()); } } }