Java Reference
In-Depth Information
event.getY());
onePath.setStrokeWidth(3);
onePath.setStroke(Color.BLACK);
onePath.getElements().add(new
MoveTo(anchorPt.getX(), anchorPt.getY()));
});
// dragging creates lineTos added to the path
scene.onMouseDraggedProperty().set((EventHandler<MouseEvent>)
(MouseEvent event) -> {
onePath.getElements().add(new
LineTo(event.getX(), event.getY()));
});
// end the path when mouse released event
scene.onMouseReleasedProperty().set((EventHandler<MouseEvent>)
(MouseEvent event) -> {
onePath.setStrokeWidth(0);
if (onePath.getElements().size() > 1) {
pathTransition.stop();
pathTransition.playFromStart();
}
});
primaryStage.setScene(scene);
primaryStage.show();
}
}
Figure 15-6 shows the drawn path the circle will follow. When the user performs a
mouse release, the drawn path will disappear and the red ball will follow the path
drawn earlier.
 
Search WWH ::




Custom Search