Professional Documents
Culture Documents
Ejemplo de Deportes
Ejemplo de Deportes
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
try {
VBox vbox1=new VBox(10);
c = new ComboBox<String>();
c.setOnAction(this); c.setPromptText("Deportes");
c.getItems().addAll("Beisbol","Basketball","Natacion
","Cricket", "Boxeo");
vbox1.getChildren().addAll(l1, c, l2);
BorderPane root = new BorderPane();
root.setTop(vbox1);
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("a
pplication.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void handle(ActionEvent event) {
// TODO Auto-generated method stub
if(event.getSource() instanceof ComboBox<?
>) {
if(c.getValue() == "Beisbol") {
l2.setText("Cantidad-> 9");
l2.setTextFill(Color.RED);}
else if(c.getValue() ==
"Basketball") {
l2.setText("Cantidad-> 11");
l2.setTextFill(Color.GREEN);}
else if(c.getValue() == "Cricket")
l2.setText("Cantidad-> 2");
else if(c.getValue() == "Natacion")
l2.setText("Cantidad-> 1");
else if(c.getValue() == "Boxeo")
l2.setText("Cantidad->2");
}
}
}