Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

java - JavaFX how to switch to different shapes

I would like to know how i can use switch or if statement to launch different shapes created into the override method start(Stage shapes).

public class Shapes extends Application {

    public String readNextLine() {
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }

    public boolean checkInput(String input)throws Exception{
        if(input == null || input.trim().length() == 0){
            throw new IOException("The input is empty or null");
        }else{
            if(!input.equals("triangle") && !input.equals("rectangle") && !input.equals("hexagon")){
                System.out.println("Check your input");
            }else {
                if(input.equals("triangle")){

                }

            }
        }

        return true;
    }

    @Override
    public void start(Stage shapes) throws Exception {

        Polygon triangle = new Polygon();
        triangle.getPoints().addAll(50.0, 0.0, 0.0, 50.0, 100.0, 50.0);

        triangle.setFill(Color.WHITE);
        triangle.setStroke(Color.BLUEVIOLET);


        // Create the HBox
        HBox root = new HBox();
        // Add the Children to the HBox
        root.getChildren().addAll(triangle);
        // Set Spacing of the HBox
        root.setSpacing(10);
        // primaryStage.setScene(new Scene(root, 300, 275));
        Scene scene = new Scene(root);
        // Add the Scene to the Stage
        shapes.setScene(scene);
        // Set the Title of the Stage
        shapes.setTitle("A JavaFX Polygon Example");
        // Display the Stage
        shapes.show();



    }


    public static void main(String[] args) throws Exception {
            launch(args);
    }
}
question from:https://stackoverflow.com/questions/66065681/javafx-how-to-switch-to-different-shapes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...