0

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);
    }
}
StoreCode
  • 155
  • 11
  • hmm ... haven't I a (basically) same question some hours ago? If so: don't delete and repost, instead edit to clarify the previous – kleopatra Feb 05 '21 at 16:46
  • 1
    Why would you be using `Scanner` for input and not a node like `TextField`? – SedJ601 Feb 05 '21 at 17:07
  • 1
    @Sedrick yes you are right. But I need to check the input. Should I use KeyEvent.KEY_TYPED? – StoreCode Feb 05 '21 at 18:50
  • The text property may be best. Try https://stackoverflow.com/questions/30160899/value-change-listener-for-javafxs-textfield – SedJ601 Feb 06 '21 at 17:48

0 Answers0