Skip to content

Instantly share code, notes, and snippets.

@JDRamosC
Created May 15, 2017 21:00
Show Gist options
  • Save JDRamosC/e37f05e95895a127a8d4e2ebad5d7d00 to your computer and use it in GitHub Desktop.
Save JDRamosC/e37f05e95895a127a8d4e2ebad5d7d00 to your computer and use it in GitHub Desktop.
JD Ramos - Practica DatePicker
package bo.edu.ubilapaz;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
DatePicker fechadatePicker = new DatePicker();
fechadatePicker.setValue(LocalDate.now());
Label imprimirFechaLabel = new Label();
Label imprimirMesLabel = new Label();
Label imprimirFechaLabelTranscurrida = new Label();
Label imprimirSignoLabel = new Label();
fechadatePicker.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
LocalDate fecha = fechadatePicker.getValue();
DateTimeFormatter formatearFecha = DateTimeFormatter.ofPattern("dd MMM yy");
//String x = formatearFecha.format(fecha);
int a = 2017 - fecha.getYear();
int b = fecha.getMonthValue() - 5;
int c = 15 - fecha.getDayOfMonth();
int dia = fecha.getDayOfMonth();
int mes = fecha.getMonthValue();
fecha.getMonthValue();
fecha.getDayOfMonth();
imprimirFechaLabel.setText("" + a);
imprimirMesLabel.setText("" +Math.abs(b));
imprimirFechaLabelTranscurrida.setText("" + c);
imprimirSignoLabel.setText(obtenerSigno(dia, mes));
}
});
System.out.println(imprimirSignoLabel);
Label ustedSeleccionoLavel = new Label("Su edad es: ");
Label ustedSeleccionoMesLabel = new Label("Los meses transcurridos son: ");
Label ustedSeleccionoDiaLabel = new Label("Los dias q transcurrieron son: ");
//System.out.println(fechadatePicker);
VBox labelTxtVBox = new VBox(20);
labelTxtVBox.getChildren().addAll(imprimirFechaLabel, imprimirFechaLabelTranscurrida, imprimirMesLabel);
VBox labelDPVBox = new VBox(20);
labelDPVBox.getChildren().addAll(ustedSeleccionoLavel, ustedSeleccionoDiaLabel, ustedSeleccionoMesLabel);
HBox primariaHBox = new HBox(40);
primariaHBox.getChildren().addAll(labelDPVBox, labelTxtVBox);
primariaHBox.setAlignment(Pos.CENTER);
VBox ventanaPrincipalVBox = new VBox(20);
ventanaPrincipalVBox.getChildren().addAll(fechadatePicker, primariaHBox, imprimirSignoLabel);
ventanaPrincipalVBox.setAlignment(Pos.CENTER);
Scene ecena = new Scene(ventanaPrincipalVBox, 500, 500);
primaryStage.setScene(ecena);
primaryStage.show();
}
private String obtenerSigno(int dia, int mes) {
String signo = "";
switch (mes) {
case 1:
if (dia > 21) {
signo = "ACUARIO";
} else {
signo = "CAPRICORNIO";
}
break;
case 2:
if (dia > 19) {
signo = "PISCIS";
} else {
signo = "ACUARIO";
}
break;
case 3:
if (dia > 20) {
signo = "ARIES";
} else {
signo = "PISCIS";
}
break;
case 4:
if (dia > 20) {
signo = "TAURO";
} else {
signo = "ARIES";
}
break;
case 5:
if (dia > 21) {
signo = "GEMINIS";
} else {
signo = "TAURO";
}
break;
case 6:
if (dia > 20) {
signo = "CANCER";
} else {
signo = "GEMINIS";
}
break;
case 7:
if (dia > 22) {
signo = "LEO";
} else {
signo = "CANCER";
}
break;
case 8:
if (dia > 21) {
signo = "VIRGO";
} else {
signo = "LEO";
}
break;
case 9:
if (dia > 22) {
signo = "LIBRA";
} else {
signo = "VIRGO";
}
break;
case 10:
if (dia > 22) {
signo = "ESCORPION";
} else {
signo = "LIBRA";
}
break;
case 11:
if (dia > 21) {
signo = "SAGITARIO";
} else {
signo = "ESCORPION";
}
break;
case 12:
if (dia > 21) {
signo = "CAPRICORNIO";
} else {
signo = "SAGITARIO";
}
break;
}
return signo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment