我需要获取名为 myGrid 的 GridPane 上指定点击的索引。如果我从我的坐标中放置一块,如下所示,它就会起作用。
例如:myGrid.add(new ImageView("othello/images/white.png"), 4, 3);
如果我想占据我在板上的点击位置,我使用此方法但没有成功。
@FXML
private void clickGrid(MouseEvent event) {
Node source = (Node)event.getSource() ;
Integer colIndex = GridPane.getColumnIndex(source);
Integer rowIndex = GridPane.getRowIndex(source);
if (colIndex != null && rowIndex != null){
myGrid.add(new ImageView("othello/images/black.png"), colIndex.intValue(), rowIndex.intValue());
}
}
如果我不使用
if (colIndex != null && rowIndex != null)
错误是“Java.NullPointEreException”
但是,如果我在程序中使用它,当我尝试获取行/列值时什么也不会发生。
帮助?谢谢
编辑:这是我的 FXML
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)