Last active
May 15, 2017 19:08
-
-
Save PabloSanchezMartinez/950838cd51fa61a67225758ab41cdbcf to your computer and use it in GitHub Desktop.
Aplicación de tiempo transcurrido
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bo.ubi.lapaz; | |
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; | |
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 diasLabel = new Label(); | |
Label mesesLabel = new Label(); | |
Label signoZodiacoLabel = new Label(); | |
fechaDatePicker.setOnAction(new EventHandler<ActionEvent>() { | |
@Override | |
public void handle(ActionEvent event) { | |
LocalDate fecha = fechaDatePicker.getValue(); | |
DateTimeFormatter formateador = DateTimeFormatter.ofPattern("dd/MMM/yyyy"); | |
String x = formateador.format(fecha); | |
int años = 2017 - fecha.getYear(); | |
int meses = 5 - fecha.getMonthValue(); | |
int dias = fecha.getDayOfMonth() + 15; | |
switch (fecha.getMonthValue()) { | |
case 1: | |
if (fecha.getDayOfMonth() > 21) { | |
signoZodiacoLabel.setText("ACUARIO"); | |
} else { | |
signoZodiacoLabel.setText("CAPRICORNIO"); | |
} | |
break; | |
case 2: | |
if (fecha.getDayOfMonth() > 19) { | |
signoZodiacoLabel.setText("PISCIS"); | |
} else { | |
signoZodiacoLabel.setText("ACUARIO"); | |
} | |
break; | |
case 3: | |
if (fecha.getDayOfMonth() > 20) { | |
signoZodiacoLabel.setText("ARIES"); | |
} else { | |
signoZodiacoLabel.setText("PISCIS"); | |
} | |
break; | |
case 4: | |
if (fecha.getDayOfMonth() > 20) { | |
signoZodiacoLabel.setText("TAURO"); | |
} else { | |
signoZodiacoLabel.setText("ARIES"); | |
} | |
break; | |
case 5: | |
if (fecha.getDayOfMonth() > 21) { | |
signoZodiacoLabel.setText("GEMINIS"); | |
} else { | |
signoZodiacoLabel.setText("TAURO"); | |
} | |
break; | |
case 6: | |
if (fecha.getDayOfMonth() > 20) { | |
signoZodiacoLabel.setText("CANCER"); | |
} else { | |
signoZodiacoLabel.setText("GEMINIS"); | |
} | |
break; | |
case 7: | |
if (fecha.getDayOfMonth() > 22) { | |
signoZodiacoLabel.setText("LEO"); | |
} else { | |
signoZodiacoLabel.setText("CANCER"); | |
} | |
break; | |
case 8: | |
if (fecha.getDayOfMonth() > 21) { | |
signoZodiacoLabel.setText("VIRGO"); | |
} else { | |
signoZodiacoLabel.setText("LEO"); | |
} | |
break; | |
case 9: | |
if (fecha.getDayOfMonth() > 22) { | |
signoZodiacoLabel.setText("LIBRA"); | |
} else { | |
signoZodiacoLabel.setText("VIRGO"); | |
} | |
break; | |
case 10: | |
if (fecha.getDayOfMonth() > 22) { | |
signoZodiacoLabel.setText("ESCORPION"); | |
} else { | |
signoZodiacoLabel.setText("LIBRA"); | |
} | |
break; | |
case 11: | |
if (fecha.getDayOfMonth() > 21) { | |
signoZodiacoLabel.setText("SAGITARIO"); | |
} else { | |
signoZodiacoLabel.setText("ESCORPION"); | |
} | |
break; | |
case 12: | |
if (fecha.getDayOfMonth() > 21) { | |
signoZodiacoLabel.setText("CAPRICORNIO"); | |
} else { | |
signoZodiacoLabel.setText("SAGITARIO"); | |
} | |
break; | |
} | |
System.out.println(años); | |
System.out.println(meses); | |
System.out.println("dias: " + dias); | |
diasLabel.setText("Transcurrieron " + años + " Años"); | |
mesesLabel.setText("Trascurrieron " + meses + "Meses"); | |
} | |
}); | |
Label textoLabel = new Label("Usted Selecciono: "); | |
HBox hbox = new HBox(); | |
hbox.getChildren().add(textoLabel); | |
hbox.getChildren().add(diasLabel); | |
VBox labelVBox = new VBox(); | |
labelVBox.getChildren().add(diasLabel); | |
labelVBox.getChildren().add(mesesLabel); | |
labelVBox.getChildren().add(signoZodiacoLabel); | |
VBox vbox = new VBox(); | |
vbox.getChildren().add(fechaDatePicker); | |
vbox.getChildren().add(hbox); | |
vbox.getChildren().add(labelVBox); | |
vbox.setAlignment(Pos.CENTER); | |
Scene ventana = new Scene(vbox, 300, 300); | |
primaryStage.setScene(ventana); | |
primaryStage.setTitle(""); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment