
ayuda Aplicacion JAVA sencilla
Publicado por alexander (2 intervenciones) el 29/10/2016 16:44:13
tengo que hacer una aplicacion con 3 combobox (dia, mes, año) para asi validar si la fecha ingresada es correcta, ya que hay años bisiestos por ende no se puede seleccionar 29 de febrero en todos los años, en ya tengo la interfaz (la vista) me haria falta el modelo y el controlador. ya tengo como rectificar los años bisiestos pero no se como enlazar los datos suministrados por el comboBox a la App
ESTA ES LA VENTANA.
y asi evaluaria los años bisiestos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package validarf;
import java.awt.FlowLayout;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ValidarF extends JFrame{
public JLabel L1,L2,L3;
public JComboBox box,box2,box3;
public JButton boton;
public ValidarF(){
L1 = new JLabel("Día:");
L2 = new JLabel("Mes:");
L3 = new JLabel("Año:");
box = new JComboBox();
for (int i = 1; i <= 31; i++){
box.addItem((i));
}
box2 = new JComboBox();
for (int o = 1; o <= 12; o++){
box2.addItem((o));}
box3 = new JComboBox();
for (int p = 1850; p <= 2017; p++){
box3.addItem((p));}
boton = new JButton("Aceptar");
getContentPane().setLayout(new FlowLayout());
add(L1);
add(box);
add(L2);
add(box2);
add(L3);
add(box3);
add(boton);
setVisible(true);
setTitle("As");
setSize(400,400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
ESTA ES LA VENTANA.
y asi evaluaria los años bisiestos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void main(String[] args) {
ValidarF a = new ValidarF();
int year = 1900; // año
int month = 2; // mes [1,...,12]
int dayOfMonth = 29; // día [1,...,31]
if (year < 1900) {
throw new IllegalArgumentException("Año inválido.");
}
LocalDate today = LocalDate.of(year, month, dayOfMonth);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
System.out.println(formatter.format(today));
}
Valora esta pregunta


0