Skip to content

Commit 453798b

Browse files
committed
Added Actividad 24 Ampliación - Unit 14
1 parent 8983815 commit 453798b

File tree

2 files changed

+313
-0
lines changed

2 files changed

+313
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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" alignment="0" attributes="0">
27+
<EmptySpace min="-2" pref="117" max="-2" attributes="0"/>
28+
<Group type="103" groupAlignment="1" attributes="0">
29+
<Group type="102" alignment="1" attributes="0">
30+
<Component id="jlTitulo" min="-2" max="-2" attributes="0"/>
31+
<EmptySpace max="32767" attributes="0"/>
32+
</Group>
33+
<Group type="102" alignment="1" attributes="0">
34+
<Component id="jlCiudad" min="-2" max="-2" attributes="0"/>
35+
<EmptySpace type="separate" max="-2" attributes="0"/>
36+
<Component id="jtfCiudad" min="-2" pref="91" max="-2" attributes="0"/>
37+
<EmptySpace min="-2" pref="128" max="-2" attributes="0"/>
38+
</Group>
39+
</Group>
40+
</Group>
41+
<Group type="102" alignment="1" attributes="0">
42+
<EmptySpace max="32767" attributes="0"/>
43+
<Group type="103" groupAlignment="1" attributes="0">
44+
<Group type="102" attributes="0">
45+
<Component id="jlCiudad2" min="-2" max="-2" attributes="0"/>
46+
<EmptySpace type="separate" max="-2" attributes="0"/>
47+
<Component id="jtfVentas" min="-2" pref="91" max="-2" attributes="0"/>
48+
</Group>
49+
<Group type="102" attributes="0">
50+
<Component id="jlCiudad1" min="-2" max="-2" attributes="0"/>
51+
<EmptySpace type="separate" max="-2" attributes="0"/>
52+
<Component id="jtfSuperficie" min="-2" pref="91" max="-2" attributes="0"/>
53+
</Group>
54+
</Group>
55+
<EmptySpace min="-2" pref="128" max="-2" attributes="0"/>
56+
</Group>
57+
<Group type="102" alignment="0" attributes="0">
58+
<EmptySpace min="-2" pref="151" max="-2" attributes="0"/>
59+
<Component id="jbCrearOficina" min="-2" max="-2" attributes="0"/>
60+
<EmptySpace max="32767" attributes="0"/>
61+
</Group>
62+
</Group>
63+
</DimensionLayout>
64+
<DimensionLayout dim="1">
65+
<Group type="103" groupAlignment="0" attributes="0">
66+
<Group type="102" alignment="0" attributes="0">
67+
<EmptySpace max="-2" attributes="0"/>
68+
<Component id="jlTitulo" min="-2" max="-2" attributes="0"/>
69+
<EmptySpace min="-2" pref="48" max="-2" attributes="0"/>
70+
<Group type="103" groupAlignment="3" attributes="0">
71+
<Component id="jlCiudad" alignment="3" min="-2" max="-2" attributes="0"/>
72+
<Component id="jtfCiudad" alignment="3" min="-2" max="-2" attributes="0"/>
73+
</Group>
74+
<EmptySpace type="separate" max="-2" attributes="0"/>
75+
<Group type="103" groupAlignment="3" attributes="0">
76+
<Component id="jlCiudad1" alignment="3" min="-2" max="-2" attributes="0"/>
77+
<Component id="jtfSuperficie" alignment="3" min="-2" max="-2" attributes="0"/>
78+
</Group>
79+
<EmptySpace type="unrelated" max="-2" attributes="0"/>
80+
<Group type="103" groupAlignment="3" attributes="0">
81+
<Component id="jlCiudad2" alignment="3" min="-2" max="-2" attributes="0"/>
82+
<Component id="jtfVentas" alignment="3" min="-2" max="-2" attributes="0"/>
83+
</Group>
84+
<EmptySpace pref="56" max="32767" attributes="0"/>
85+
<Component id="jbCrearOficina" min="-2" max="-2" attributes="0"/>
86+
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
87+
</Group>
88+
</Group>
89+
</DimensionLayout>
90+
</Layout>
91+
<SubComponents>
92+
<Component class="javax.swing.JLabel" name="jlTitulo">
93+
<Properties>
94+
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
95+
<Font name="Helvetica Neue" size="18" style="0"/>
96+
</Property>
97+
<Property name="text" type="java.lang.String" value="Crear Oficina"/>
98+
</Properties>
99+
</Component>
100+
<Component class="javax.swing.JLabel" name="jlCiudad">
101+
<Properties>
102+
<Property name="text" type="java.lang.String" value="Ciudad:"/>
103+
</Properties>
104+
</Component>
105+
<Component class="javax.swing.JTextField" name="jtfCiudad">
106+
</Component>
107+
<Component class="javax.swing.JLabel" name="jlCiudad1">
108+
<Properties>
109+
<Property name="text" type="java.lang.String" value="Superficie:"/>
110+
</Properties>
111+
</Component>
112+
<Component class="javax.swing.JTextField" name="jtfSuperficie">
113+
</Component>
114+
<Component class="javax.swing.JLabel" name="jlCiudad2">
115+
<Properties>
116+
<Property name="text" type="java.lang.String" value="Ventas:"/>
117+
</Properties>
118+
</Component>
119+
<Component class="javax.swing.JTextField" name="jtfVentas">
120+
</Component>
121+
<Component class="javax.swing.JButton" name="jbCrearOficina">
122+
<Properties>
123+
<Property name="text" type="java.lang.String" value="Crear"/>
124+
</Properties>
125+
<Events>
126+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jbCrearOficinaActionPerformed"/>
127+
</Events>
128+
</Component>
129+
</SubComponents>
130+
</Form>
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
2+
package unit14.Actividad24_Ampliacion;
3+
4+
import javax.swing.JOptionPane;
5+
import unit14.Actividad15_Aplicacion.DAO.OficinaDAO;
6+
import unit14.Actividad15_Aplicacion.Oficina;
7+
8+
9+
public class Actividad24 extends javax.swing.JFrame {
10+
11+
12+
public Actividad24() {
13+
initComponents();
14+
}
15+
16+
@SuppressWarnings("unchecked")
17+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
18+
private void initComponents() {
19+
20+
jlTitulo = new javax.swing.JLabel();
21+
jlCiudad = new javax.swing.JLabel();
22+
jtfCiudad = new javax.swing.JTextField();
23+
jlCiudad1 = new javax.swing.JLabel();
24+
jtfSuperficie = new javax.swing.JTextField();
25+
jlCiudad2 = new javax.swing.JLabel();
26+
jtfVentas = new javax.swing.JTextField();
27+
jbCrearOficina = new javax.swing.JButton();
28+
29+
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
30+
31+
jlTitulo.setFont(new java.awt.Font("Helvetica Neue", 0, 18)); // NOI18N
32+
jlTitulo.setText("Crear Oficina");
33+
34+
jlCiudad.setText("Ciudad:");
35+
36+
jlCiudad1.setText("Superficie:");
37+
38+
jlCiudad2.setText("Ventas:");
39+
40+
jbCrearOficina.setText("Crear");
41+
jbCrearOficina.addActionListener(new java.awt.event.ActionListener() {
42+
public void actionPerformed(java.awt.event.ActionEvent evt) {
43+
jbCrearOficinaActionPerformed(evt);
44+
}
45+
});
46+
47+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
48+
getContentPane().setLayout(layout);
49+
layout.setHorizontalGroup(
50+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
51+
.addGroup(layout.createSequentialGroup()
52+
.addGap(117, 117, 117)
53+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
54+
.addGroup(layout.createSequentialGroup()
55+
.addComponent(jlTitulo)
56+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
57+
.addGroup(layout.createSequentialGroup()
58+
.addComponent(jlCiudad)
59+
.addGap(18, 18, 18)
60+
.addComponent(jtfCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
61+
.addGap(128, 128, 128))))
62+
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
63+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
64+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
65+
.addGroup(layout.createSequentialGroup()
66+
.addComponent(jlCiudad2)
67+
.addGap(18, 18, 18)
68+
.addComponent(jtfVentas, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
69+
.addGroup(layout.createSequentialGroup()
70+
.addComponent(jlCiudad1)
71+
.addGap(18, 18, 18)
72+
.addComponent(jtfSuperficie, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
73+
.addGap(128, 128, 128))
74+
.addGroup(layout.createSequentialGroup()
75+
.addGap(151, 151, 151)
76+
.addComponent(jbCrearOficina)
77+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
78+
);
79+
layout.setVerticalGroup(
80+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
81+
.addGroup(layout.createSequentialGroup()
82+
.addContainerGap()
83+
.addComponent(jlTitulo)
84+
.addGap(48, 48, 48)
85+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
86+
.addComponent(jlCiudad)
87+
.addComponent(jtfCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
88+
.addGap(18, 18, 18)
89+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
90+
.addComponent(jlCiudad1)
91+
.addComponent(jtfSuperficie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
92+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
93+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
94+
.addComponent(jlCiudad2)
95+
.addComponent(jtfVentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
96+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
97+
.addComponent(jbCrearOficina)
98+
.addGap(45, 45, 45))
99+
);
100+
101+
pack();
102+
}// </editor-fold>//GEN-END:initComponents
103+
104+
private void jbCrearOficinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCrearOficinaActionPerformed
105+
String ciudad = jtfCiudad.getText();
106+
String superficieString = jtfSuperficie.getText();
107+
String ventasString = jtfVentas.getText();
108+
boolean isValidOficina = true;
109+
String errorMessage = "";
110+
111+
if (ciudad.isBlank()) {
112+
isValidOficina = false;
113+
errorMessage = "La ciudad no puede estar vacía";
114+
} else if (!superficieString.matches("\\d+")) {
115+
isValidOficina = false;
116+
errorMessage = "La superficie debe de ser numérica";
117+
} else if (Integer.parseInt(superficieString) <= 0) {
118+
isValidOficina = false;
119+
errorMessage = "La superficie no puede ser negativa";
120+
} else if (!ventasString.matches("\\d+")) {
121+
isValidOficina = false;
122+
errorMessage = "Las ventas debe de ser numérica";
123+
} else if (Integer.parseInt(ventasString) <= 0) {
124+
isValidOficina = false;
125+
errorMessage = "Las ventas no puede ser negativa";
126+
}
127+
128+
if (!isValidOficina) {
129+
JOptionPane.showMessageDialog(this, errorMessage,"Error", JOptionPane.ERROR_MESSAGE);
130+
} else {
131+
OficinaDAO oficinaDAO = new OficinaDAO();
132+
Oficina nuevaOficina = new Oficina(0, ciudad, Integer.parseInt(superficieString), Integer.valueOf(ventasString));
133+
134+
oficinaDAO.insert(nuevaOficina);
135+
}
136+
}//GEN-LAST:event_jbCrearOficinaActionPerformed
137+
138+
/**
139+
* @param args the command line arguments
140+
*/
141+
public static void main(String args[]) {
142+
/* Set the Nimbus look and feel */
143+
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
144+
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
145+
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
146+
*/
147+
try {
148+
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
149+
if ("Nimbus".equals(info.getName())) {
150+
javax.swing.UIManager.setLookAndFeel(info.getClassName());
151+
break;
152+
}
153+
}
154+
} catch (ClassNotFoundException ex) {
155+
java.util.logging.Logger.getLogger(Actividad24.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
156+
} catch (InstantiationException ex) {
157+
java.util.logging.Logger.getLogger(Actividad24.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
158+
} catch (IllegalAccessException ex) {
159+
java.util.logging.Logger.getLogger(Actividad24.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
160+
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
161+
java.util.logging.Logger.getLogger(Actividad24.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
162+
}
163+
//</editor-fold>
164+
165+
/* Create and display the form */
166+
java.awt.EventQueue.invokeLater(new Runnable() {
167+
public void run() {
168+
new Actividad24().setVisible(true);
169+
}
170+
});
171+
}
172+
173+
// Variables declaration - do not modify//GEN-BEGIN:variables
174+
private javax.swing.JButton jbCrearOficina;
175+
private javax.swing.JLabel jlCiudad;
176+
private javax.swing.JLabel jlCiudad1;
177+
private javax.swing.JLabel jlCiudad2;
178+
private javax.swing.JLabel jlTitulo;
179+
private javax.swing.JTextField jtfCiudad;
180+
private javax.swing.JTextField jtfSuperficie;
181+
private javax.swing.JTextField jtfVentas;
182+
// End of variables declaration//GEN-END:variables
183+
}

0 commit comments

Comments
 (0)