简体   繁体   English

如何从 Choicebox 获取 int 值

[英]How do get int value from Choicebox

i need help with my choiceBox to connect it with a button to verify the choice i made.我需要有关我的 choiceBox 的帮助,以将其与按钮连接以验证我所做的选择。 the task i currently working on is a Ferry Simulator so for example i want to embark a car with passengers, the amount of passengers should be selected from the choicebox and the embark the car with a button.我目前正在处理的任务是一个渡轮模拟器,所以例如我想乘坐载有乘客的汽车,应从选择框中选择乘客数量,然后使用按钮登上汽车。 To Embark the vehicle you must have int value in to the car object, my Question is how can i get int from choicebox and how can i connect it to the Button.要上车,您必须对汽车 object 具有整数值,我的问题是如何从选择框获取整数以及如何将其连接到按钮。 Thanks谢谢

    ChoiceBox cbCar = new ChoiceBox();
    cbCar.getItems().addAll("0 Passengers",1,2,3,4);
    cbCar.getSelectionModel();
    cbCar.setLayoutX(100);
    cbCar.setLayoutY(65); 

    // Button for car 
    Button bCar = new Button("Embark");
    bCar.setLayoutX(220);
    bCar.setLayoutY(65);
    bCar.setOnAction(event -> {     
       Car ca = new Car(int passengers );   // from the choicebox   
        ferry.embark(ca)    });
choiceBox.getValue().toString(); 

This can be used to display the selected value.这可用于显示所选值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM