I'm trying to draw a polygon in javafx adding to its array of point the mouse coordinates. My problem is that I don't know how to make it stop when I click something else from the mouse left click.
Polygon polygon = new Polygon();
rootPane.setOnMouseClicked((MouseEvent mouseEvent) -> {
do {
polygon.getPoints().addAll(mouseEvent.getX(),mouseEvent.getY());
} while(mouseEvent.getButton().equals(mouseEvent.isSecondaryButtonDown()));
});
rootPane.getChildren().add(polygon);