Skip to content

Commit 405e50f

Browse files
committed
Added Actividad 25 Ampliación - Unit 14
1 parent 5007c94 commit 405e50f

File tree

3 files changed

+298
-0
lines changed

3 files changed

+298
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="3"/>
6+
</Properties>
7+
<SyntheticProperties>
8+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
9+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
10+
</SyntheticProperties>
11+
<AuxValues>
12+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
13+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
14+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
15+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
16+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
17+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
18+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
19+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
20+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
21+
</AuxValues>
22+
23+
<Layout>
24+
<DimensionLayout dim="0">
25+
<Group type="103" groupAlignment="0" attributes="0">
26+
<Group type="102" attributes="0">
27+
<Group type="103" groupAlignment="0" attributes="0">
28+
<Group type="102" alignment="0" attributes="0">
29+
<EmptySpace min="-2" pref="150" max="-2" attributes="0"/>
30+
<Component id="jlTitulo" min="-2" max="-2" attributes="0"/>
31+
</Group>
32+
<Group type="102" alignment="0" attributes="0">
33+
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
34+
<Component id="jScrollPane1" min="-2" pref="318" max="-2" attributes="0"/>
35+
</Group>
36+
</Group>
37+
<EmptySpace pref="46" max="32767" attributes="0"/>
38+
</Group>
39+
</Group>
40+
</DimensionLayout>
41+
<DimensionLayout dim="1">
42+
<Group type="103" groupAlignment="0" attributes="0">
43+
<Group type="102" alignment="0" attributes="0">
44+
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
45+
<Component id="jlTitulo" min="-2" max="-2" attributes="0"/>
46+
<EmptySpace type="separate" max="-2" attributes="0"/>
47+
<Component id="jScrollPane1" min="-2" pref="239" max="-2" attributes="0"/>
48+
<EmptySpace max="32767" attributes="0"/>
49+
</Group>
50+
</Group>
51+
</DimensionLayout>
52+
</Layout>
53+
<SubComponents>
54+
<Component class="javax.swing.JLabel" name="jlTitulo">
55+
<Properties>
56+
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
57+
<Font name="Helvetica Neue" size="18" style="0"/>
58+
</Property>
59+
<Property name="text" type="java.lang.String" value="Empleados"/>
60+
</Properties>
61+
</Component>
62+
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
63+
<AuxValues>
64+
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
65+
</AuxValues>
66+
67+
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
68+
<SubComponents>
69+
<Component class="javax.swing.JTable" name="jtListaEmpleados">
70+
<Properties>
71+
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
72+
<Table columnCount="4" rowCount="4">
73+
<Column editable="true" title="Title 1" type="java.lang.Object"/>
74+
<Column editable="true" title="Title 2" type="java.lang.Object"/>
75+
<Column editable="true" title="Title 3" type="java.lang.Object"/>
76+
<Column editable="true" title="Title 4" type="java.lang.Object"/>
77+
</Table>
78+
</Property>
79+
</Properties>
80+
</Component>
81+
</SubComponents>
82+
</Container>
83+
</SubComponents>
84+
</Form>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package unit14.Actividad25_Ampliacion;
2+
3+
import java.time.format.DateTimeFormatter;
4+
import java.util.ArrayList;
5+
import javax.swing.table.AbstractTableModel;
6+
import unit14.Actividad15_Aplicacion.Empleado;
7+
8+
/**
9+
*
10+
* @author deifont
11+
*/
12+
public class ModeloListaEmpleados extends AbstractTableModel{
13+
public final static DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy");
14+
15+
16+
private ArrayList<Empleado> listaEmpleados;
17+
private final String [] nombresColumnas = {"Nombre", "Edad", "Puesto", "Contrato"};
18+
19+
public ModeloListaEmpleados(){
20+
this.listaEmpleados = new ArrayList<>();
21+
}
22+
23+
public void añadirEmpleado(Empleado e){
24+
this.listaEmpleados.add(e);
25+
this.fireTableDataChanged();
26+
}
27+
public boolean eliminarEmpleado (int index) {
28+
boolean empleadoEliminada = false;
29+
if (index >= 0 && index < listaEmpleados.size()) {
30+
listaEmpleados.remove(index);
31+
empleadoEliminada = true;
32+
}
33+
return empleadoEliminada;
34+
}
35+
36+
public Empleado getEmpleado(int index) {
37+
Empleado empleado = null;
38+
if (index >= 0 && index < listaEmpleados.size()) {
39+
empleado = new Empleado(listaEmpleados.get(index));
40+
}
41+
return empleado;
42+
}
43+
44+
public void updateRow (int row) {
45+
this.fireTableRowsUpdated(row, row);
46+
}
47+
48+
49+
@Override
50+
public String getColumnName(int index){
51+
return this.nombresColumnas[index];
52+
}
53+
54+
@Override
55+
public int getRowCount() {
56+
return this.listaEmpleados.size();
57+
}
58+
59+
@Override
60+
public int getColumnCount() {
61+
return nombresColumnas.length;
62+
}
63+
64+
@Override
65+
public Object getValueAt(int row, int column) {
66+
Empleado c = listaEmpleados.get(row);
67+
Object value = null;
68+
switch(column){
69+
case 0 -> value = c.getNombre();
70+
case 1 -> value = c.getEdad();
71+
case 2 -> value = c.getPuesto();
72+
case 3 -> value = FORMATTER.format(c.getContrato());
73+
}
74+
return value;
75+
}
76+
77+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy