Javafx click on a Circle and get it's reference
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a set of Nodes, Circles, on the stage. I want to be able to click on one of them and 'select it' (just get a reference to it so I can move it around, change color etc.) Pane root = new Pane(); root.getChildren().addAll( /* an array of Circle objects */ ); Scene scene = new Scene(root, 500, 500, BACKGROUND_COLOR); scene.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { // how do I get which Circle I clicked on? } }); stage.setTitle(TITLE); stage.setScene(scene); stage.show(); 回答1: