-
-
Save alvareztech/aa89a2c7468fedd463c313603ef5e4ec to your computer and use it in GitHub Desktop.
JavaFX: Aplicación Zodiaco
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
import javafx.application.Application; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.geometry.Insets; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Label; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
public class Main extends Application { | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
TextField dia = new TextField(); | |
dia.setPromptText("Día"); | |
TextField mes = new TextField(); | |
mes.setPromptText("Mes"); | |
Label mensaje = new Label("Este es un mensaje"); | |
Button boton1 = new Button("Calcular"); | |
boton1.setOnAction(new EventHandler<ActionEvent>() { | |
@Override | |
public void handle(ActionEvent event) { | |
int miDia = Integer.parseInt(dia.getText()); | |
int miMes = Integer.parseInt(mes.getText()); | |
String signo = obtenerSigno(miDia, miMes); | |
mensaje.setText("Su signo es: " + signo); | |
} | |
}); | |
VBox caja = new VBox(); | |
caja.getChildren().add(dia); | |
caja.getChildren().add(mes); | |
caja.getChildren().add(boton1); | |
caja.getChildren().add(mensaje); | |
caja.setSpacing(15); | |
caja.setPadding(new Insets(20, 20, 20, 20)); | |
Scene scene = new Scene(caja, 300, 200); | |
primaryStage.setScene(scene); | |
primaryStage.setTitle("Zodiaco"); | |
primaryStage.show(); | |
} | |
public static 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