You are on page 1of 2

package application;

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;

public class provinciass extends Application


implements EventHandler<ActionEvent> {
Label l1, l2;
ComboBox<String> c;

@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");

l1 = new Label("Deportes ");


l2 = new Label(" ");

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();
}
}

public static void main(String[] args) {


launch(args);
}

@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");
}
}
}

You might also like