How to draw Polylines in Javafx?

Asked

Viewed 107 times

1

How do I draw Polylines on a canvas in Javafx? I’m trying to do something similar:

public void start(Stage stage) {
        VBox box = new VBox();
        final Scene scene = new Scene(box, 300, 250);
        scene.setFill(null);

        double x=0.0,y=0.0;
        EventHandler filter = new EventHandler<InputEvent>() {
            @Override
            public void handle(InputEvent event) {
                     Line line = new Line();
        line.setStartX(0.0f);
        line.setStartY(0.0f);
        line.setEndX(100.0f);
        line.setEndY(100.0f);
        box.getChildren().add(line);


            }
        };
// Register the same filter for two different nodes
        scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

        stage.setScene(scene);
        stage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }

But it accuses error that within events I can not use either root or any of those variables that I would leave from Polyline. Someone can help me... or post a code using these data structures that I used (so it’s not so confusing).... thanks :D

  • You can’t understand the doubt, I compiled and ran without any mistakes.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.