如何在JavaFX中获得精确的鼠标位置?
我可以像这样在按钮上添加鼠标事件:
btnTriangle.setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent me)
{
//I NEED TO GET THE X and Y Coordinates from the Mouse
}
});
我需要X和Y值来显示一些特殊的内容......
感谢您的帮助!
答案 0 :(得分:1)
只需在代码中添加2行就可以获得它们,如James_D所说:
btnTriangle.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
System.out.println("Coordinate X -> " + me.getX());
System.out.println("Coordinate Y -> " + me.getY());
}
});