import javax.swing.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import java.awt.*;

public class Aplicacion {
public static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
String horarios="",fechaLeida="",fecha2="",horaLeida2="";
for (;;) {
System.out.println("\n ********************* ESCUELA POLITECNICA NACIONAL *********************\n");
System.out.println("1.- Presentación");
System.out.println("2.- Validación de fecha y hora");
System.out.println("3.- Salir");
System.out.println("\nSeleccione una opcion:\n");
switch (leerOpcion(1,3)) {

case 1:
JOptionPane.showMessageDialog(null," ESCUELA POLITECNICA NACIONAL "+"\n\n"+" Electrónica y Redes de la Información"

+"\n\n"+" Realizado por: "+"\n"+ " Poogramers "+"\n\n","\t\tPresentacion",JOptionPane.PLAIN_MESSAGE);
break;

case 2:
fechaLeida=JOptionPane.showInputDialog(null,"Ingrese la fecha con el siguiente formato dd/mm/aa"+"\n"+"Ejemplo: 17/05/1987");
boolean cumplefecha = Pattern.matches("^(((0[1-9]
[12][0-9]
3[01])/(0[13578]
10
12)/\\d{4})
(([0][1-9]
[12][0-9]
30)/(0[469]
11)/\\d{4})
((0[1-9]
1[0-9]
2[0-8])/(02)/\\d{4})
((29).
-
/(02)/([02468][048]00))
((29)/(02)/([13579][26]00))
((29)/(02)/([0-9][0-9][0][48]))
((29)/(02)/([0-9][0-9][2468][048]))
((29)/(02)/([0-9][0-9][13579][26])))", fechaLeida);
boolean patronfecha = Pattern.matches("^\\d{2}\\/\\d{2}\\/\\d{4}$", fechaLeida);
for(;;){
if(patronfecha==true && cumplefecha==true)
{
JOptionPane.showMessageDialog(null,"La fecha ingresada es válida", "Correcto",JOptionPane.INFORMATION_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null, "La fecha ingresada no es válida\n", "Error",JOptionPane.ERROR_MESSAGE);
fecha2=fechaLeida;
fecha2=JOptionPane.showInputDialog(null,"Ingrese la fecha con el siguiente formato dd/mm/aa"+"\n"+"Ejemplo: 17/05/1987");
boolean cumplefecha2 = Pattern.matches("^(((0[1-9]
[12][0-9]
3[01])/(0[13578]
10
12)/\\d{4})
(([0][1-9]
[12][0-9]
30)/(0[469]
11)/\\d{4})
((0[1-9]
1[0-9]
2[0-8])/(02)/\\d{4})
((29).
-
/(02)/([02468][048]00))
((29)/(02)/([13579][26]00))
((29)/(02)/([0-9][0-9][0][48]))
((29)/(02)/([0-9][0-9][2468][048]))
((29)/(02)/([0-9][0-9][13579][26])))", fecha2);
boolean patronfecha2 = Pattern.matches("^\\d{2}\\/\\d{2}\\/\\d{4}$", fecha2);
if(patronfecha2==true && cumplefecha2==true)
{
JOptionPane.showMessageDialog(null,"La fecha ingresada es válida", "Correcto",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
String horaLeida=JOptionPane.showInputDialog(null,"Ingrese la hora con el siguiente formato HH : MM : SS"+"\n"+"Ejemplo: 22:03:24");
boolean cumplehora = Pattern.matches("^(0[0-9]
1[0-9]
2[0-3]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9])$", horaLeida);
boolean horario = Pattern.matches("^(0[0-9]
1[01]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9])$", horaLeida);
boolean patron = Pattern.matches("^\\d{2}\\:\\d{2}\\:\\d{2}$", horaLeida);
for(;;){
if(patron==true && cumplehora==true)
{
JOptionPane.showMessageDialog(null,"La hora ingresada es válida");
if(horario==true)
{
horarios="mañana";
}
else
{
horarios="tarde";
}
break;
}
else
{
JOptionPane.showMessageDialog(null, "La hora ingresada no es válida", "Error",JOptionPane.ERROR_MESSAGE);
horaLeida2=JOptionPane.showInputDialog(null,"Ingrese la hora con el siguiente formato HH : MM : SS"+"\n"+"Ejemplo: 22:03:24");
boolean cumplehora2 = Pattern.matches("^(0[0-9]
1[0-9]
2[0-3]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9])$", horaLeida2);
boolean horario2 = Pattern.matches("^(0[0-9]
1[01]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9]):(0[0-9]
1[0-9]
2[0-9]
3[0-9]
4[0-9]
5[0-9])$", horaLeida2);
boolean patron2 = Pattern.matches("^\\d{2}\\:\\d{2}\\:\\d{2}$", horaLeida2);
if(patron2==true && cumplehora2==true)
{
JOptionPane.showMessageDialog(null,"La hora ingresada es válida");
if(horario2==true)
{
horarios="mañana";
}
else
{
horarios="tarde";
}
break;
}
}
}

JPanel panel, caja;
final JTextArea resultado;
String salida;
panel = new JPanel();
caja = new JPanel();
caja.setLayout(new GridLayout(0, 1));
salida = "\n\n\n ";
resultado = new JTextArea(salida);
resultado.setEditable(false);
panel.setLayout(new BorderLayout(100, 10));
panel.add(caja, BorderLayout.CENTER);
panel.add(resultado, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
if(cumplefecha==true && patronfecha==true && cumplehora==true && patron==true){
String mensaje = "\t VALORES INGRESADOS\n\n\tFecha: \t\t" + fechaLeida + "\n\tHora: \t\t" + horaLeida+ "\n\n Usted a ingresado la fecha " + fechaLeida + " a las " + horaLeida + " de la " +horarios;
resultado.setText(mensaje);
}
if((cumplefecha==false
patronfecha==false) && cumplehora==true && patron==true){
String mensaje = "\t VALORES INGRESADOS\n\n\tFecha: \t\t" + fecha2 + "\n\tHora: \t\t" + horaLeida+ "\n\n Usted a ingresado la fecha " + fecha2 + " a las " + horaLeida + " de la " +horarios;
resultado.setText(mensaje);
}
if(cumplefecha==true && patronfecha==true && (cumplehora==false
patron==false)){
String mensaje = "\t VALORES INGRESADOS\n\n\tFecha: \t\t" + fechaLeida + "\n\tHora: \t\t" + horaLeida2+ "\n\n Usted a ingresado la fecha " + fechaLeida + " a las " + horaLeida2 + " de la " +horarios;
resultado.setText(mensaje);
}
if(cumplefecha==false && patronfecha==false && cumplehora==false && patron==false){
String mensaje = "\t VALORES INGRESADOS\n\n\tFecha: \t\t" + fecha2 + "\n\tHora: \t\t" + horaLeida2+ "\n\n Usted a ingresado la fecha " + fecha2 + " a las " + horaLeida2 + " de la " +horarios;
resultado.setText(mensaje);
}
if((cumplefecha==false
patronfecha==false) && (cumplehora==false
patron==false)){
String mensaje = "\t VALORES INGRESADOS\n\n\tFecha: \t\t" + fecha2 + "\n\tHora: \t\t" + horaLeida2+ "\n\n Usted a ingresado la fecha " + fecha2 + " a las " + horaLeida2 + " de la " +horarios;
resultado.setText(mensaje);
}
JFrame f = new JFrame("VERIFICADOR DE FECHA Y HORA - JORGE GUIJARRO");
f.add(panel);
f.setBounds(100, 100, 450, 180);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
break;

case 3:
JOptionPane.showMessageDialog(null,"Programa Finalizado... ");
System.exit(0);
default:
JOptionPane.showMessageDialog(null,"\nSu seleccion fue incorrecta.\n", "Error",JOptionPane.ERROR_MESSAGE);
}
}
}
public static int leerOpcion(double limInf, double limSup) {
do {
try {
int numero;
numero = Integer.parseInt(stdIn.readLine());
if (numero >= limInf && numero <= limSup){
return numero;
} else {
throw new Exception();
}
}catch (Exception e) {
JOptionPane.showMessageDialog(null,"Su seleccion fue incorrecta... ", "Error",JOptionPane.ERROR_MESSAGE);
System.out.println("\nSeleccione una opcion:\n");
}
}while (true);
}
}

1 comentario:

  1. Colegas les agradezco haber creado este blog, por fin he encontrado un scrip q funcionas, les felicito por el trabajo, muchas garcias..!!

    si necesitan colaboracion escriban a mi correo johnstamos@hispavista.com

    ResponderEliminar

Seguidores