|
| 1 | +/* |
| 2 | + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license |
| 3 | + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template |
| 4 | + */ |
| 5 | +package unit14.Actividad25_Ampliacion; |
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import unit14.Actividad15_Aplicacion.DAO.EmpleadoDAO; |
| 9 | +import unit14.Actividad15_Aplicacion.Empleado; |
| 10 | + |
| 11 | +/** |
| 12 | + * |
| 13 | + * @author josemaria |
| 14 | + */ |
| 15 | +public class Actividad25 extends javax.swing.JFrame { |
| 16 | + |
| 17 | + /** |
| 18 | + * Creates new form Actividad25 |
| 19 | + */ |
| 20 | + public Actividad25() { |
| 21 | + initComponents(); |
| 22 | + inicializar(); // Inicializamos la tabla |
| 23 | + } |
| 24 | + |
| 25 | + private void inicializar() { |
| 26 | + EmpleadoDAO empleadoDAO = new EmpleadoDAO(); // Creamos el DAO |
| 27 | + modelo = new ModeloListaEmpleados(); // Creamos el modelo |
| 28 | + |
| 29 | + ArrayList<Empleado> empleados = (ArrayList<Empleado>) empleadoDAO.readAll(); // Leemos todos los empleados |
| 30 | + for (Empleado e : empleados) { // Añadimos los empleados al modelo |
| 31 | + modelo.añadirEmpleado(e); |
| 32 | + } |
| 33 | + |
| 34 | + jtListaEmpleados.setModel(modelo); // Asignamos el modelo a la tabla |
| 35 | + |
| 36 | + |
| 37 | + } |
| 38 | + /** |
| 39 | + * This method is called from within the constructor to initialize the form. |
| 40 | + * WARNING: Do NOT modify this code. The content of this method is always |
| 41 | + * regenerated by the Form Editor. |
| 42 | + */ |
| 43 | + @SuppressWarnings("unchecked") |
| 44 | + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| 45 | + private void initComponents() { |
| 46 | + |
| 47 | + jlTitulo = new javax.swing.JLabel(); |
| 48 | + jScrollPane1 = new javax.swing.JScrollPane(); |
| 49 | + jtListaEmpleados = new javax.swing.JTable(); |
| 50 | + |
| 51 | + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
| 52 | + |
| 53 | + jlTitulo.setFont(new java.awt.Font("Helvetica Neue", 0, 18)); // NOI18N |
| 54 | + jlTitulo.setText("Empleados"); |
| 55 | + |
| 56 | + jtListaEmpleados.setModel(new javax.swing.table.DefaultTableModel( |
| 57 | + new Object [][] { |
| 58 | + {null, null, null, null}, |
| 59 | + {null, null, null, null}, |
| 60 | + {null, null, null, null}, |
| 61 | + {null, null, null, null} |
| 62 | + }, |
| 63 | + new String [] { |
| 64 | + "Title 1", "Title 2", "Title 3", "Title 4" |
| 65 | + } |
| 66 | + )); |
| 67 | + jScrollPane1.setViewportView(jtListaEmpleados); |
| 68 | + |
| 69 | + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
| 70 | + getContentPane().setLayout(layout); |
| 71 | + layout.setHorizontalGroup( |
| 72 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 73 | + .addGroup(layout.createSequentialGroup() |
| 74 | + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 75 | + .addGroup(layout.createSequentialGroup() |
| 76 | + .addGap(150, 150, 150) |
| 77 | + .addComponent(jlTitulo)) |
| 78 | + .addGroup(layout.createSequentialGroup() |
| 79 | + .addGap(36, 36, 36) |
| 80 | + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE))) |
| 81 | + .addContainerGap(46, Short.MAX_VALUE)) |
| 82 | + ); |
| 83 | + layout.setVerticalGroup( |
| 84 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 85 | + .addGroup(layout.createSequentialGroup() |
| 86 | + .addGap(16, 16, 16) |
| 87 | + .addComponent(jlTitulo) |
| 88 | + .addGap(18, 18, 18) |
| 89 | + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE) |
| 90 | + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
| 91 | + ); |
| 92 | + |
| 93 | + pack(); |
| 94 | + }// </editor-fold>//GEN-END:initComponents |
| 95 | + |
| 96 | + /** |
| 97 | + * @param args the command line arguments |
| 98 | + */ |
| 99 | + public static void main(String args[]) { |
| 100 | + /* Set the Nimbus look and feel */ |
| 101 | + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> |
| 102 | + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. |
| 103 | + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html |
| 104 | + */ |
| 105 | + try { |
| 106 | + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { |
| 107 | + if ("Nimbus".equals(info.getName())) { |
| 108 | + javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
| 109 | + break; |
| 110 | + } |
| 111 | + } |
| 112 | + } catch (ClassNotFoundException ex) { |
| 113 | + java.util.logging.Logger.getLogger(Actividad25.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 114 | + } catch (InstantiationException ex) { |
| 115 | + java.util.logging.Logger.getLogger(Actividad25.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 116 | + } catch (IllegalAccessException ex) { |
| 117 | + java.util.logging.Logger.getLogger(Actividad25.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 118 | + } catch (javax.swing.UnsupportedLookAndFeelException ex) { |
| 119 | + java.util.logging.Logger.getLogger(Actividad25.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 120 | + } |
| 121 | + //</editor-fold> |
| 122 | + |
| 123 | + /* Create and display the form */ |
| 124 | + java.awt.EventQueue.invokeLater(new Runnable() { |
| 125 | + public void run() { |
| 126 | + new Actividad25().setVisible(true); |
| 127 | + } |
| 128 | + }); |
| 129 | + } |
| 130 | + |
| 131 | + private ModeloListaEmpleados modelo; |
| 132 | + // Variables declaration - do not modify//GEN-BEGIN:variables |
| 133 | + private javax.swing.JScrollPane jScrollPane1; |
| 134 | + private javax.swing.JLabel jlTitulo; |
| 135 | + private javax.swing.JTable jtListaEmpleados; |
| 136 | + // End of variables declaration//GEN-END:variables |
| 137 | +} |
0 commit comments