如何使用javafx显示对象的字符串方法?

时间:2016-07-11 11:40:55

标签: java javafx instance-variables

主要方法是在Calculate extends EnemyType类中。 switch语句有9个案例 嵌套在while循环中 每个实例化一个子类 然后构造EnemyType。 (这应该是一个uml图表还是什么?) void calc()方法在系统输出中显示结果, 结束switch语句, 返回到Calculate main()方法的循环。

此类尝试使用javafx.scene.control.ComboBox;触发嵌套的switch语句。我认为问题介于descriptionpane或子类中的setAll()void方法之间。我希望子类setAll()void方法的内容显示在descriptonpane或label或其他东西中。但现在它只打印到控制台。

@Override
public void start(Stage primaryStage) {
    DescriptionPane D = new DescriptionPane();
    Label lbl = new Label();

    ComboBox<String> cboTypes = new ComboBox<>();
    ObservableList<String> items = FXCollections.observableArrayList
      ("Light Grineer", "Medium Grineer", "Heavy Grineer", 
              "Light Corpus", "Medium Corpus", "Heavy Corpus",
              "Light Infested", "Medium Infested", "Heavy Infested");
    cboTypes.getItems().addAll(items);
    cboTypes.setValue(items.get(0));
    cboTypes.setOnAction(e -> {

        currentIndex = items.indexOf(cboTypes.getValue());

        switch(currentIndex){
        case 1: System.out.println("LightGrineer"); new LightGrineer().setAll();
        case 2: System.out.println("MediumGrineer"); new MediumGrineer().setAll(); break;
        case 3: System.out.println("HeavyGrineer"); new HeavyGrineer().setAll(); break;
        case 4: System.out.println("LightCorpus"); new LightCorpus().setAll(); break;
        case 5: System.out.println("MediumCorpus"); new MediumCorpus().setAll(); break;
        case 6: System.out.println("HeavyCorpus"); new HeavyCorpus().setAll(); break;
        case 7: System.out.println("LightInfested"); new LightInfested().setAll(); break;
        case 8: System.out.println("MediumInfested"); new MediumInfested().setAll(); break;
        case 9: System.out.println("HeavyInfested"); new HeavyInfested().setAll(); break;

    }
      });
    VBox vBox = new VBox(20);
    vBox.getChildren().add(D);
    vBox.setAlignment(Pos.CENTER_LEFT);

    HBox hBox = new HBox(10);
    hBox.getChildren().addAll(new Label("Choose Enemy Type: "), cboTypes);
    hBox.setAlignment(Pos.CENTER);


    BorderPane pane = new BorderPane();
    pane.setBottom(hBox);
    pane.setLeft(vBox);

    // Create a scene and place it in the stage
    Scene scene = new Scene(pane, 900, 400);
    primaryStage.setTitle("EnemyTypes_by_JohnRyan"); // Set the stage title
    primaryStage.setScene(scene); // Place the scene in the stage
    primaryStage.show(); // Display the stage  

}

0 个答案:

没有答案