· 9 years ago · Oct 05, 2016, 12:32 PM
1Print from Correos.java: rere@gmail.com
2Print from RegistroEstudiante.java: null
3
4package escuela;
5import javax.swing.Box;
6import javax.swing.JLabel;
7import javax.swing.JOptionPane;
8import javax.swing.JPanel;
9import javax.swing.*;
10
11import org.apache.commons.lang3.StringUtils;
12
13public class Estudiante {
14
15public static void main(String[] args) {
16RegistroEstudiante estudiante = new RegistroEstudiante();
17
18 estudiante.inicio();
19}
20
21
22}
23
24package escuela;
25import javax.swing.JOptionPane;
26import org.apache.commons.lang3.StringUtils;
27
28public class RegistroEstudiante{
29
30private int matricula = 0; //Sólo 6 dÃgitos
31private byte edad = 0; //No menor de 0
32private float altura = 0.0F;
33private String nombre = null, menu = null, ape_paterno = null, ape_materno = null, correo = null, genero = null, estadoCivil;
34private int length = 0;
35private boolean error = false;
36
37public void inicio() {
38 String[] menuPrincipal = { "Ingresar", "Mostrar", "Salir" };
39 String[] genero = { "Masculino", "Femenino" };
40 String[] estadoCivilMenu = { "Soltero/a", "Comprometido/a", "Casado/a", "Divorciado/a", "Viudo/a" };
41 Correos Correos = new Correos();
42 do {
43 try {
44 setMenu((String)JOptionPane.showInputDialog(null, "¿Qué deseas hacer?", "UNACAR", JOptionPane.QUESTION_MESSAGE, null, menuPrincipal, menuPrincipal[0]));
45
46 switch(getMenu()) {
47 case "Ingresar":
48 do{
49 setError(false);
50 try {
51 setMatricula(Integer.parseInt((String)JOptionPane.showInputDialog(null, "Introduce MatrÃcula [6]", "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null)));
52 } catch (java.lang.NumberFormatException e) {
53 JOptionPane.showMessageDialog(null, "Introdujiste un caractér inválido", "Error", JOptionPane.ERROR_MESSAGE, null);
54 setError(true);
55 }
56 length = (int)(Math.log10(getMatricula())+1); // Saca cantidad de caracteres
57 if ( (length != 6) && (error == false) )
58 {
59 JOptionPane.showMessageDialog(null, "La MatrÃcula DEBE ser de 6 dÃgitos", "Error", JOptionPane.ERROR_MESSAGE, null);
60 setMatricula(0);
61 }
62 } while (length != 6);
63
64 //SET NOMBRE
65 do{
66 setError(false);
67 setNombre((String)JOptionPane.showInputDialog(null, "Introduce nombre del alumno", "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null));
68 if(StringUtils.isAlpha(getNombre()) == false)
69 {
70 JOptionPane.showMessageDialog(null, "El nombre debe contener únicamente letras [A-Za-z]", "Error", JOptionPane.ERROR_MESSAGE, null);
71 setNombre(null);
72 setError(true);
73 }
74
75 }while(isError() == true);
76
77 //SET APELLIDO PATERNO
78 do{
79 setError(false);
80 setApe_paterno((String)JOptionPane.showInputDialog(null, "Introduce apellido paterno de " + getNombre(), "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null));
81 if(StringUtils.isAlpha(getApe_paterno()) == false)
82 {
83 JOptionPane.showMessageDialog(null, "El apellido debe contener únicamente letras [A-Za-z]", "Error", JOptionPane.ERROR_MESSAGE, null);
84 setApe_paterno(null);
85 setError(true);
86 }
87
88 }while(isError() == true);
89
90 //SET APellido MATERNO FTW
91
92 do{
93 setError(false);
94 setApe_materno((String)JOptionPane.showInputDialog(null, "Introduce apellido materno de " + getNombre(), "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null));
95 if(StringUtils.isAlpha(getApe_materno()) == false)
96 {
97 JOptionPane.showMessageDialog(null, "El nombre debe contener únicamente letras [A-Za-z]", "Error", JOptionPane.ERROR_MESSAGE, null);
98 setApe_materno(null);
99 setError(true);
100 }
101
102 }while(isError() == true);
103
104 // SELECCIONA SEXO
105
106 if(JOptionPane.showOptionDialog(null, "Selecciona género de " + getNombre(), "Agregando estudiante", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, genero, genero[0]) == 0 ){
107 setGenero("Masculino");
108 }else{
109 setGenero("Femenino");
110 }
111
112 // SET ESTADO CIVIL COMPA
113
114 setEstadoCivil((String)JOptionPane.showInputDialog(null, "Estado Civil de " + getNombre(), "UNACAR", JOptionPane.QUESTION_MESSAGE, null, estadoCivilMenu, estadoCivilMenu[0]));
115
116 // SET EDAD
117 do{
118 setError(false);
119 try {
120 setEdad(Byte.parseByte((String)JOptionPane.showInputDialog(null, "Introduce la edad del alumno", "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null)));
121 } catch (java.lang.NumberFormatException e) {
122 JOptionPane.showMessageDialog(null, "Aquà no se aceptan números...", "Error", JOptionPane.ERROR_MESSAGE, null);
123 setError(true);
124 }
125 if(getEdad() < 0)
126 {
127 JOptionPane.showMessageDialog(null, getNombre() + " no puede tener 0 años o menos, corrige... ", "Error", JOptionPane.ERROR_MESSAGE, null);
128 setEdad((byte) 0);
129 setError(true);
130 }
131
132 }while(isError() == true);
133
134
135 //SET ALTURA
136
137 do{
138 setError(false);
139 try {
140 setAltura(Float.parseFloat((String)JOptionPane.showInputDialog(null, "Introduce la altura del alumno", "Agregando estudiante", JOptionPane.QUESTION_MESSAGE, null, null, null)));
141 } catch (java.lang.NumberFormatException e) {
142 JOptionPane.showMessageDialog(null, "Aquà no se aceptan letras...", "Error", JOptionPane.ERROR_MESSAGE, null);
143 setError(true);
144 }
145
146 if(getAltura() < 0)
147 {
148 JOptionPane.showMessageDialog(null, getNombre() + " no puede medir 0 centimetros o menos, corrige...", "Error", JOptionPane.ERROR_MESSAGE, null);
149 setAltura(0.0F);
150 setError(true);
151 }
152
153 }while(isError() == true);
154
155 // SetMail
156 escuela.Correos.main();
157
158 do {
159 try {
160 // setCorreo(correos.getCorreoConcatenado());
161 System.out.println("En RegistroEstudiante.java " + correo);
162 Thread.sleep(1000);
163
164 } catch (InterruptedException e) {
165 // TODO Auto-generated catch block
166 e.printStackTrace();
167 }
168 } while (correo == null);
169 break;
170
171 case "Mostrar":
172 break;
173
174
175 } // END SWITCH
176 }// END TRY
177 catch (java.lang.NullPointerException e) {
178 switch(JOptionPane.showConfirmDialog(null, "¿Seguro que deseas salir?", "Salir o no salir?.. He ahà la cuestión...", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null)) {
179 case 0:
180 return;
181
182 case 1:
183 break;
184 }
185 }
186 } while (getMenu() != "Salir");
187
188}
189
190public boolean sonLetras(String name) {
191 return name.matches("[a-zA-Z]+");
192}
193
194public int getMatricula() {
195 return matricula;
196}
197
198public void setMatricula(int matricula) {
199 this.matricula = matricula;
200}
201
202public byte getEdad() {
203 return edad;
204}
205
206public void setEdad(byte edad) {
207 if(edad < 0)
208 JOptionPane.showMessageDialog(null, "No se aceptan valores menores a 0", "Error", JOptionPane.WARNING_MESSAGE, null);
209 this.edad = edad;
210}
211
212public float getAltura() {
213 return altura;
214}
215
216public void setAltura(float altura) {
217 this.altura = altura;
218}
219
220public String getNombre() {
221 return nombre;
222}
223
224public void setNombre(String nombre) {
225 this.nombre = nombre;
226}
227
228public String getApe_paterno() {
229 return ape_paterno;
230}
231
232public void setApe_paterno(String ape_paterno) {
233 this.ape_paterno = ape_paterno;
234}
235
236public String getApe_materno() {
237 return ape_materno;
238}
239
240public void setApe_materno(String ape_materno) {
241 this.ape_materno = ape_materno;
242}
243
244public String getCorreo() {
245 return correo;
246}
247
248public void setCorreo(String correo) {
249 this.correo = correo;
250}
251
252
253
254public int getLength() {
255 return length;
256}
257
258
259
260public void setLength(int length) {
261 this.length = length;
262}
263
264
265
266public boolean isError() {
267 return error;
268}
269
270
271
272public void setError(boolean error) {
273 this.error = error;
274}
275
276
277public String getGenero() {
278 return genero;
279}
280
281
282public void setGenero(String genero) {
283 this.genero = genero;
284}
285
286
287public String getEstadoCivil() {
288 return estadoCivil;
289}
290
291
292public void setEstadoCivil(String estadoCivil) {
293 this.estadoCivil = estadoCivil;
294}
295
296public String getMenu() {
297 return menu;
298}
299
300public void setMenu(String menu) {
301 this.menu = menu;
302}
303
304}
305
306package escuela;
307
308import java.awt.Component;
309import java.awt.EventQueue;
310import java.awt.Font;
311import java.awt.event.ActionEvent;
312import java.awt.event.ActionListener;
313import java.awt.event.MouseAdapter;
314import java.awt.event.MouseEvent;
315
316import javax.swing.DefaultComboBoxModel;
317import javax.swing.JButton;
318import javax.swing.JComboBox;
319import javax.swing.JFrame;
320import javax.swing.JLabel;
321import javax.swing.JPopupMenu;
322import javax.swing.JTextField;
323
324import org.eclipse.wb.swing.FocusTraversalOnArray;
325import java.awt.Window.Type;
326
327public class Correos {
328
329private JFrame frmAgregandoEstudiante;
330private JTextField txtUsuario;
331private String correoConcatenado = null;
332
333/**
334 * Launch the application.
335 */
336public static void main() {
337 EventQueue.invokeLater(new Runnable() {
338 public void run() {
339 try {
340 Correos window = new Correos();
341 window.frmAgregandoEstudiante.setVisible(true);
342 } catch (Exception e) {
343 e.printStackTrace();
344 }
345 }
346 });
347}
348
349/**
350 * Create the application.
351 */
352public Correos() {
353 initialize();
354}
355
356/**
357 * Initialize the contents of the frame.
358 */
359private void initialize() {
360 frmAgregandoEstudiante = new JFrame();
361 frmAgregandoEstudiante.setAlwaysOnTop(true);
362 frmAgregandoEstudiante.setResizable(false);
363 frmAgregandoEstudiante.setTitle("Agregando estudiante");
364 frmAgregandoEstudiante.setBounds(100, 100, 272, 164);
365 frmAgregandoEstudiante.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
366 frmAgregandoEstudiante.getContentPane().setLayout(null);
367
368 txtUsuario = new JTextField();
369 txtUsuario.setToolTipText("Introduce la primera parte de tu correo");
370 txtUsuario.setBounds(10, 48, 104, 30);
371 frmAgregandoEstudiante.getContentPane().add(txtUsuario);
372 txtUsuario.setColumns(10);
373
374 JComboBox comboBox = new JComboBox();
375 comboBox.setModel(new DefaultComboBoxModel(new String[] {"@gmail.com", "@outlook.com", "@unacar.mx", "@live.com", "@yahoo.com", "@hotmail.com"}));
376 comboBox.setBounds(124, 48, 119, 30);
377 frmAgregandoEstudiante.getContentPane().add(comboBox);
378
379 JButton btnAgregar = new JButton("Agregar");
380 btnAgregar.addActionListener(new ActionListener() {
381 public void actionPerformed(ActionEvent arg0) {
382 String user,mail;
383 RegistroEstudiante re = new RegistroEstudiante();
384
385 user = txtUsuario.getText();
386 mail = (String) comboBox.getSelectedItem();
387 setCorreoConcatenado(user.concat(mail));
388 re.setCorreo(getCorreoConcatenado());
389 System.out.println("re.setcorreo " + re.getCorreo());
390
391
392 }
393 });
394 btnAgregar.setBounds(77, 89, 89, 23);
395 frmAgregandoEstudiante.getContentPane().add(btnAgregar);
396
397 JLabel lblNewLabel = new JLabel("Agrega el correo del estudiante");
398 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
399 lblNewLabel.setBounds(10, 11, 207, 27);
400 frmAgregandoEstudiante.getContentPane().add(lblNewLabel);
401 frmAgregandoEstudiante.getContentPane().setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{txtUsuario, comboBox, btnAgregar}));
402}
403private static void addPopup(Component component, final JPopupMenu popup) {
404 component.addMouseListener(new MouseAdapter() {
405 public void mousePressed(MouseEvent e) {
406 if (e.isPopupTrigger()) {
407 showMenu(e);
408 }
409 }
410 public void mouseReleased(MouseEvent e) {
411 if (e.isPopupTrigger()) {
412 showMenu(e);
413 }
414 }
415 private void showMenu(MouseEvent e) {
416 popup.show(e.getComponent(), e.getX(), e.getY());
417 }
418 });
419}
420
421public String getCorreoConcatenado() {
422 return correoConcatenado;
423}
424
425public void setCorreoConcatenado(String correoConcatenado) {
426 this.correoConcatenado = correoConcatenado;
427}
428}