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 GUI; import DAO.UsuarioNoExisteException; import MODELO.DetalleFactura; import MODELO.Factura; import MODELO.Usuario; import SERVICIO.FacturaSERVICIO; import SERVICIO.UsuarioSERVICIO; import com.itextpdf.text.Element; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Color; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import org.josql.QueryExecutionException; import org.josql.QueryParseException; /** * * @author Christian Quinde <christian24091992@gmail.com> */ public class FacturasUsuariosGUI extends javax.swing.JFrame { /** * Creates new form FacturasUsuariosGUI */ UsuarioSERVICIO us = new UsuarioSERVICIO(); FacturaSERVICIO fs = new FacturaSERVICIO(); private DefaultTableModel modeloUsuarioFacturas; private DefaultTableModel modeloFacturas; private DefaultTableModel modeloDetallesFactura; public FacturasUsuariosGUI() { try { initComponents(); setIconImage(new ImageIcon(getClass().getResource("/IMG/parking.png")).getImage()); this.setLocationRelativeTo(null); modeloUsuarioFacturas = (DefaultTableModel) listarFacturasUsuarios.getModel(); modeloFacturas = (DefaultTableModel) listarFacturas.getModel(); modeloDetallesFactura = (DefaultTableModel) listarDetallesFactura.getModel(); alinearDatos(listarFacturasUsuarios, listarFacturasUsuarios.getColumnCount()); alinearDatos(listarFacturas, listarFacturas.getColumnCount()); alinearDatos(listarDetallesFactura, listarDetallesFactura.getColumnCount()); presentarUsuariosFacturas(); } catch (UsuarioNoExisteException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } catch (QueryExecutionException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (QueryParseException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } } /** * 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() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); listarDetallesFactura = new javax.swing.JTable(); jPanel6 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); nombresTXT = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); apellidosTXT = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); cedulaTXT = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); placasTXT = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); telefonoTXT = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); marcaTXT = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); modeloTXT = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); fechaTXT = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); horaTXT = new javax.swing.JTextField(); jPanel7 = new javax.swing.JPanel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); subtotalTXT = new javax.swing.JTextField(); ivaTXT = new javax.swing.JTextField(); totalTXT = new javax.swing.JTextField(); jPanel3 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); listarFacturasUsuarios = new javax.swing.JTable(); jPanel4 = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); listarFacturas = new javax.swing.JTable(); jButton4 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jLabel14 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMaximumSize(new java.awt.Dimension(940, 460)); setMinimumSize(new java.awt.Dimension(940, 460)); setPreferredSize(new java.awt.Dimension(940, 460)); setSize(new java.awt.Dimension(940, 460)); getContentPane().setLayout(null); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder( javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)), "Datos de Usuarios Registrados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel1.setForeground(new java.awt.Color(255, 255, 255)); jPanel1.setOpaque(false); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DatosFactura", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel2.setForeground(new java.awt.Color(255, 255, 255)); jPanel2.setOpaque(false); jPanel5.setBackground(new java.awt.Color(153, 153, 153)); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalles de Factura", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel5.setOpaque(false); listarDetallesFactura.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Fecha y hora de entrada", "Fecha y hora de salida", "Tiempo" }) { boolean[] canEdit = new boolean[] { false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); listarDetallesFactura.setEnabled(false); jScrollPane3.setViewportView(listarDetallesFactura); if (listarDetallesFactura.getColumnModel().getColumnCount() > 0) { listarDetallesFactura.getColumnModel().getColumn(1).setResizable(false); listarDetallesFactura.getColumnModel().getColumn(2).setMinWidth(125); listarDetallesFactura.getColumnModel().getColumn(2).setMaxWidth(125); } javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane3)); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)); jPanel6.setBackground(new java.awt.Color(153, 153, 153)); jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel6.setOpaque(false); jLabel2.setBackground(new java.awt.Color(204, 204, 204)); jLabel2.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("Nombres : "); jLabel2.setOpaque(true); nombresTXT.setEditable(false); jLabel3.setBackground(new java.awt.Color(204, 204, 204)); jLabel3.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Apellidos : "); jLabel3.setOpaque(true); apellidosTXT.setEditable(false); jLabel4.setBackground(new java.awt.Color(204, 204, 204)); jLabel4.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel4.setForeground(new java.awt.Color(255, 255, 255)); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("Cedula : "); jLabel4.setOpaque(true); cedulaTXT.setEditable(false); jLabel6.setBackground(new java.awt.Color(204, 204, 204)); jLabel6.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel6.setForeground(new java.awt.Color(255, 255, 255)); jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel6.setText("Placas : "); jLabel6.setOpaque(true); placasTXT.setEditable(false); placasTXT.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N placasTXT.setHorizontalAlignment(javax.swing.JTextField.CENTER); jLabel5.setBackground(new java.awt.Color(204, 204, 204)); jLabel5.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel5.setForeground(new java.awt.Color(255, 255, 255)); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText("Telefono : "); jLabel5.setOpaque(true); telefonoTXT.setEditable(false); jLabel7.setBackground(new java.awt.Color(204, 204, 204)); jLabel7.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel7.setForeground(new java.awt.Color(255, 255, 255)); jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel7.setText("Marca : "); jLabel7.setOpaque(true); marcaTXT.setEditable(false); jLabel8.setBackground(new java.awt.Color(204, 204, 204)); jLabel8.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel8.setForeground(new java.awt.Color(255, 255, 255)); jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel8.setText("Modelo : "); jLabel8.setOpaque(true); modeloTXT.setEditable(false); jLabel12.setBackground(new java.awt.Color(204, 204, 204)); jLabel12.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel12.setForeground(new java.awt.Color(255, 255, 255)); jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel12.setText("Fecha : "); jLabel12.setOpaque(true); fechaTXT.setEditable(false); jLabel13.setBackground(new java.awt.Color(204, 204, 204)); jLabel13.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel13.setForeground(new java.awt.Color(255, 255, 255)); jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel13.setText("Hora : "); jLabel13.setOpaque(true); horaTXT.setEditable(false); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(6, 6, 6) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout .createSequentialGroup() .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(placasTXT, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cedulaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(12, 12, 12) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel5) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(telefonoTXT, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(marcaTXT, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(modeloTXT, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout .createSequentialGroup().addComponent(fechaTXT).addGap(18, 18, 18) .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(horaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(nombresTXT).addComponent(apellidosTXT, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap())); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel12).addComponent(fechaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(nombresTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel3).addComponent(apellidosTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel4).addComponent(cedulaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel7).addComponent(marcaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel8).addComponent(modeloTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup().addGroup(jPanel6Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(placasTXT)).addGap(26, 26, 26)))) .addGroup(jPanel6Layout.createSequentialGroup().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel13).addComponent(horaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel6Layout.createSequentialGroup().addGap(78, 78, 78).addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER).addComponent(jLabel5) .addComponent(telefonoTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(74, 74, 74))); jPanel7.setBackground(new java.awt.Color(153, 153, 153)); jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Valor a pagar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel7.setOpaque(false); jLabel9.setBackground(new java.awt.Color(204, 204, 204)); jLabel9.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel9.setForeground(new java.awt.Color(255, 255, 255)); jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel9.setText("Total : "); jLabel9.setOpaque(true); jLabel10.setBackground(new java.awt.Color(204, 204, 204)); jLabel10.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel10.setForeground(new java.awt.Color(255, 255, 255)); jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel10.setText("Subtotal : "); jLabel10.setOpaque(true); jLabel11.setBackground(new java.awt.Color(204, 204, 204)); jLabel11.setFont(new java.awt.Font("Calibri Light", 0, 12)); // NOI18N jLabel11.setForeground(new java.awt.Color(255, 255, 255)); jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel11.setText("Iva : "); jLabel11.setOpaque(true); subtotalTXT.setFont(new java.awt.Font("Calibri Light", 1, 18)); // NOI18N subtotalTXT.setForeground(new java.awt.Color(102, 102, 102)); subtotalTXT.setHorizontalAlignment(javax.swing.JTextField.CENTER); subtotalTXT.setEnabled(false); ivaTXT.setFont(new java.awt.Font("Calibri Light", 1, 18)); // NOI18N ivaTXT.setForeground(new java.awt.Color(102, 102, 102)); ivaTXT.setHorizontalAlignment(javax.swing.JTextField.CENTER); ivaTXT.setEnabled(false); totalTXT.setFont(new java.awt.Font("Calibri Light", 1, 18)); // NOI18N totalTXT.setForeground(new java.awt.Color(102, 102, 102)); totalTXT.setHorizontalAlignment(javax.swing.JTextField.CENTER); totalTXT.setEnabled(false); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addComponent(jLabel10) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(subtotalTXT, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup() .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(totalTXT, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE) .addComponent(ivaTXT)))) .addContainerGap())); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGap(20, 20, 20).addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER).addComponent(jLabel10) .addComponent(subtotalTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(ivaTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel11)) .addGap(20, 20, 20) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(totalTXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2Layout .setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanel3.setBackground(new java.awt.Color(255, 255, 255)); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel3.setForeground(new java.awt.Color(255, 255, 255)); jPanel3.setOpaque(false); listarFacturasUsuarios.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Cdula", "Nombres", "Apellidos", "Telefono" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); listarFacturasUsuarios.setOpaque(false); listarFacturasUsuarios.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { listarFacturasUsuariosMouseClicked(evt); } }); jScrollPane1.setViewportView(listarFacturasUsuarios); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout .setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)); jPanel4.setBackground(new java.awt.Color(255, 255, 255)); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Facturas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N jPanel4.setForeground(new java.awt.Color(255, 255, 255)); jPanel4.setOpaque(false); listarFacturas.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "N", "Cdula", "Fecha", "Estado" }) { boolean[] canEdit = new boolean[] { false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); listarFacturas.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { listarFacturasMouseClicked(evt); } }); jScrollPane2.setViewportView(listarFacturas); if (listarFacturas.getColumnModel().getColumnCount() > 0) { listarFacturas.getColumnModel().getColumn(0).setMinWidth(30); listarFacturas.getColumnModel().getColumn(0).setMaxWidth(30); listarFacturas.getColumnModel().getColumn(1).setMinWidth(75); listarFacturas.getColumnModel().getColumn(1).setMaxWidth(75); listarFacturas.getColumnModel().getColumn(3).setResizable(false); } javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout .setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)); jButton4.setText("Generar factura"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton3.setForeground(new java.awt.Color(255, 0, 0)); jButton3.setText("Salir"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Cdula : "); jButton1.setText("Buscar"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(14, 14, 14).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(555, Short.MAX_VALUE))))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3).addComponent(jButton4))) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); getContentPane().add(jPanel1); jPanel1.setBounds(10, 11, 900, 402); jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMG/fondo3.png"))); // NOI18N getContentPane().add(jLabel14); jLabel14.setBounds(-10, -10, 940, 450); pack(); }// </editor-fold>//GEN-END:initComponents private void listarFacturasUsuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listarFacturasUsuariosMouseClicked try { int fila = listarFacturasUsuarios.rowAtPoint(evt.getPoint()); String cedula = (String) listarFacturasUsuarios.getValueAt(fila, 0); Usuario usuario = us.recuperarUsuario(cedula); LinkedList<Factura> facturas = fs.recuperarFacturas(cedula); cargarTablaFacturas(cedula, facturas); } catch (QueryParseException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (QueryExecutionException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (UsuarioNoExisteException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); // }catch(NullPointerException ex){ } }//GEN-LAST:event_listarFacturasUsuariosMouseClicked private void listarFacturasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listarFacturasMouseClicked try { int fila = listarFacturas.rowAtPoint(evt.getPoint()); String cedula = (String) listarFacturas.getValueAt(fila, 1); Usuario usuario = us.recuperarUsuario(cedula); LinkedList<Factura> factura = fs.recuperarFacturas(cedula); cargarDetallesDeFacturas(usuario, factura.getFirst()); } catch (QueryParseException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (QueryExecutionException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } catch (UsuarioNoExisteException ex) { Logger.getLogger(FacturasUsuariosGUI.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_listarFacturasMouseClicked private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed this.setVisible(false); ParqueaderoMAINGUI pmg = new ParqueaderoMAINGUI(); pmg.setVisible(true); }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed try { int fila = listarFacturas.getSelectedRow(); if (fila != -1) { String cedula = (String) modeloFacturas.getValueAt(fila, 1); String numeroFactura = (String) modeloFacturas.getValueAt(fila, 0); SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Usuario u = us.recuperarUsuario(cedula); LinkedList<Factura> f = fs.recuperarFacturas(cedula); com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.LETTER, 50, 50, 50, 50); Image imagen, publicidad; imagen = Image.getInstance("src//IMG//logohd.png"); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scalePercent(60f); //publicidad // publicidad = Image.getInstance("LOGO.png"); // publicidad.setAlignment(Element.ALIGN_CENTER); // publicidad.scalePercent(40f); // Document doc = new Document(); // PdfWriter PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("factura.pdf")); document.open(); document.add(imagen); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph( "| FACTURAS PARQUEADERO |")); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph("RUC: 0102030405067 ")); document.add(new Paragraph("Numero Fact: 00000" + numeroFactura)); document.add(new Paragraph("Cliente : " + u.getNombre() + " " + u.getApellido())); document.add(new Paragraph("N de cdula : " + u.getCedula())); document.add( new Paragraph("Fecha : " + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()))); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph("Placas : " + u.getVehiculo().getPlaca())); document.add(new Paragraph("Marca : " + u.getVehiculo().getMarca())); document.add(new Paragraph("Modelo : " + u.getVehiculo().getModelo())); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph( "| N | FECHA Y HORA DE ENTRADA | FECHA Y HORA DE SALIDA | TIEMPO |")); for (int i = 0; i < f.get(fila).getListaDetalleFacturas().size(); i++) { document.add(new Paragraph("| " + (i + 1) + " | " + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraEntrada()) + " | " + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraSalida()) + " | " + f.get(fila).getListaDetalleFacturas().get(i).getTiempo() + " |")); } document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph(" Subtotal : " + f.get(fila).getSubtotal())); document.add(new Paragraph(" Iva : " + f.get(fila).getIva())); document.add(new Paragraph(" Total : " + f.get(fila).getTotal())); document.add(new Paragraph( "____________________________________________________________________________")); document.add(new Paragraph( "____________________________________________________________________________")); document.close(); File path = new File("factura.pdf"); Desktop.getDesktop().open(path); this.setVisible(false); new ParqueaderoMAINGUI().setVisible(true); } else { JOptionPane.showMessageDialog(this, "Para generar un pdf debe seleccionar alguna factura"); } } catch (Exception e) { } }//GEN-LAST:event_jButton4ActionPerformed /** * @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(FacturasUsuariosGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(FacturasUsuariosGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(FacturasUsuariosGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(FacturasUsuariosGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FacturasUsuariosGUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField apellidosTXT; private javax.swing.JTextField cedulaTXT; private javax.swing.JTextField fechaTXT; private javax.swing.JTextField horaTXT; private javax.swing.JTextField ivaTXT; private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; 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.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTextField jTextField1; private javax.swing.JTable listarDetallesFactura; private javax.swing.JTable listarFacturas; private javax.swing.JTable listarFacturasUsuarios; private javax.swing.JTextField marcaTXT; private javax.swing.JTextField modeloTXT; private javax.swing.JTextField nombresTXT; private javax.swing.JTextField placasTXT; private javax.swing.JTextField subtotalTXT; private javax.swing.JTextField telefonoTXT; private javax.swing.JTextField totalTXT; // End of variables declaration//GEN-END:variables private void presentarUsuariosFacturas() throws UsuarioNoExisteException, QueryExecutionException, QueryParseException { limpiarUsuariosFacturas(); limpiarDetallesDeFacturas(); List<Usuario> usuarios = us.recuperarUsuarios(); for (Iterator<Usuario> usu = usuarios.iterator(); usu.hasNext();) { Usuario u = usu.next(); if (fs.existeFactura(u.getCedula())) { modeloUsuarioFacturas .addRow(new Object[] { u.getCedula(), u.getNombre(), u.getApellido(), u.getTelefono() }); } } } private void limpiarUsuariosFacturas() { int b = modeloUsuarioFacturas.getRowCount() - 1; for (int i = b; i >= 0; i--) { modeloUsuarioFacturas.removeRow(i); } } private void cargarTablaFacturas(String cedula, LinkedList<Factura> facturas) { limpiarTablaFacturas(); limpiarDetallesDeFacturas(); System.out.println("fac:"); int cont = 1; for (Iterator<Factura> iterator = facturas.iterator(); iterator.hasNext();) { Factura f = iterator.next(); modeloFacturas.addRow(new Object[] { Integer.toString(cont), cedula, new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(f.getTiempo()), f.getEstadoFactura().estadoFactura() }); cont++; } } private void limpiarTablaFacturas() { int b = modeloFacturas.getRowCount() - 1; for (int i = b; i >= 0; i--) { modeloFacturas.removeRow(i); } } private void cargarDetallesDeFacturas(Usuario usuario, Factura factura) { //presenta los datos del usuario en el formulario ademas de los detalles de factura como tambien el total fechaTXT.setText(new SimpleDateFormat("dd/MM/yyyy").format(factura.getTiempo())); horaTXT.setText(new SimpleDateFormat("HH:mm:ss").format(factura.getTiempo())); nombresTXT.setText(usuario.getNombre()); apellidosTXT.setText(usuario.getApellido()); cedulaTXT.setText(usuario.getCedula()); telefonoTXT.setText(usuario.getTelefono()); placasTXT.setText(usuario.getVehiculo().getPlaca()); marcaTXT.setText(usuario.getVehiculo().getMarca()); modeloTXT.setText(usuario.getVehiculo().getModelo()); subtotalTXT.setText(Double.toString(redondear(factura.getSubtotal(), 2))); ivaTXT.setText(Double.toString(redondear(factura.getIva(), 2))); totalTXT.setText(Double.toString(redondear(factura.getTotal(), 2))); SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); for (Iterator<DetalleFactura> iterator = factura.getListaDetalleFacturas().iterator(); iterator .hasNext();) { DetalleFactura detalle = iterator.next(); modeloDetallesFactura.addRow(new Object[] { fecha.format(detalle.getFechaHoraEntrada()), fecha.format(detalle.getFechaHoraSalida()), detalle.getTiempo() }); } } private void limpiarDetallesDeFacturas() { fechaTXT.setText(""); horaTXT.setText(""); nombresTXT.setText(""); apellidosTXT.setText(""); cedulaTXT.setText(""); telefonoTXT.setText(""); placasTXT.setText(""); marcaTXT.setText(""); modeloTXT.setText(""); subtotalTXT.setText(""); ivaTXT.setText(""); totalTXT.setText(""); int b = modeloDetallesFactura.getRowCount() - 1; for (int i = b; i >= 0; i--) { modeloDetallesFactura.removeRow(i); } } public static double redondear(double numero, int decimales) { return Math.round(numero * Math.pow(10, decimales)) / Math.pow(10, decimales); } private void alinearDatos(JTable tabla, int numeroColumnas) { DefaultTableCellRenderer AlinearDatos = new DefaultTableCellRenderer(); AlinearDatos.setHorizontalAlignment(SwingConstants.CENTER);//.LEFT .RIGHT .CENTER DefaultTableCellRenderer AlinearHeader = new DefaultTableCellRenderer(); AlinearHeader.setHorizontalAlignment(SwingConstants.CENTER);//.LEFT .RIGHT .CENTER AlinearHeader.setVerticalAlignment(SwingConstants.CENTER); AlinearHeader.setBackground(Color.LIGHT_GRAY); AlinearHeader.setForeground(Color.white); JTableHeader header = tabla.getTableHeader(); header.setDefaultRenderer(AlinearHeader); tabla.setTableHeader(header); for (int i = 0; i < numeroColumnas; i++) { tabla.getColumnModel().getColumn(i).setCellRenderer(AlinearDatos); } } }