0

我一直在尝试编写这个 Javafx gui 程序,但是当尝试使用 getValue() 方法时,它最终会说“它找不到那个符号”。即使我尝试使用该方法的演示。我怎样才能让这个方法工作,当用户从组合框中选择一个选项时,有没有其他方法可以让代码运行?

没有显示我的进口商品,因为它们很多。

public class LogoMaster3000 extends Application {

    BorderPane border;
    HBox hbox;
    Canvas can;
    AnchorPane ap;
    Scene scene;
    Button shapesComboBox;
   // Desktop desktop = Desktop.getDesktop();
    TextField tx;
    @Override
    public void start(Stage primaryStage) {

        border = new BorderPane();
        hbox = addHBox();
        border.setTop(hbox);
        border.setLeft(addVBox());
        addStackPane(hbox);  // Add stack to HBox in top region

        can = new Canvas();

        can.setStyle("-fx-background-color: #E8EACD");


        AnchorPane wrapperPane = new AnchorPane();
        border.setCenter(wrapperPane);
        scene = new Scene(border, 1000, 600);

        primaryStage.setTitle("LogoMaker 3000");
        primaryStage.setScene(scene);
        primaryStage.show();

        shapesComboBox.setOnAction(
                new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {

                        if (shapesComboBox.getValue == "Square"){

                            Rectangle square = new Rectangle(50, 50);
                            square.setFill(Color.BLACK);
                            DragResizeMod.makeResizable(square, null);

                            wrapperPane.getChildren().add(square);
                        }
                        if (shapesComboBox.getValue == "Rectangle"){

                            Rectangle rectangle = new Rectangle(50, 50);
                            rectangle.setFill(Color.BLACK);
                            DragResizeMod.makeResizable(rectangle, null);

                            wrapperPane.getChildren().add(rectangle);
                        }
                        if (shapesComboBox.getValue == "Triangle"){

                            Polygon polygon = new Polygon();
                            polygon.getPoints().addAll(new Double[]{
                                    75, 0,
                                    50, 50,
                                    100, 100
                            })

                            polygon.setFill(Color.BLACK);
                            DragResizeMod.makeResizable(polygon, null);

                            wrapperPane.getChildren().add(polygon);
                        }
                        if (shapesComboBox.getValue == "Circle"){

                            Circle circle = new Circle(100,100,50);
                            circle.setFill(Color.BLACK);
                            DragResizeMod.makeResizable(circle, null)

                            wrapperPane.getChildren().add(circle);
                        }
                    }
                }
        );


    }


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}
 public void addStackPane(HBox hb) {
    StackPane stack = new StackPane();
    Rectangle helpIcon = new Rectangle(30.0, 25.0);
    helpIcon.setFill(new LinearGradient(0,0,0,1, true, CycleMethod.NO_CYCLE,
        new Stop[]{
        new Stop(0,Color.web("#4977A3")),
        new Stop(0.5, Color.web("#B0C6DA")),
        new Stop(1,Color.web("#9CB6CF")),}));
    helpIcon.setStroke(Color.web("#D0E6FA"));
    helpIcon.setArcHeight(3.5);
    helpIcon.setArcWidth(3.5);

    Text helpText = new Text("?");
    helpText.setFont(Font.font("Verdana", FontWeight.BOLD, 18));
    helpText.setFill(Color.WHITE);
    helpText.setStroke(Color.web("#7080A0")); 

    stack.getChildren().addAll(helpIcon, helpText);
    stack.setAlignment(Pos.CENTER_RIGHT);     // Right-justify nodes in stack
    StackPane.setMargin(helpText, new Insets(0, 10, 0, 0)); // Center "?"

    hb.getChildren().add(stack);            // Add to HBox from Example 1-2
    HBox.setHgrow(stack, Priority.ALWAYS);    // Give stack any extra space
}  

 public VBox addVBox() {
     VBox vbox = new VBox();
     vbox.setPadding(new Insets(10));
     vbox.setSpacing(8);

     Text title = new Text("Logo Maker");
     title.setFont(Font.font("Arial", FontWeight.BOLD, 14));
     vbox.getChildren().add(title);

     final ComboBox shapesComboBox = new ComboBox();
     shapesComboBox.getItems().addAll(
             "Square",
             "Rectangle",
             "Triangle",
             "Circle",
             "Pyramid",
             "Cube",
             "Sphere"

     );

     shapesComboBox.setPromptText("Shapes");
     shapesComboBox.setMaxWidth(Double.MAX_VALUE);
     vbox.getChildren().add(shapesComboBox);

    return vbox;
 }

}
4

0 回答 0