我正在尝试使用addMouseListener
. 它没有显示任何错误,我什至可以添加一个mouseClicked(MouseEvent e)
,并且仍然没有错误。但最后,当我尝试使用它获取当前位置时,worldWindowGLCanvas1.getCurrentPosition()
它显示为 NULL,即使我点击地球或外部......有人可以帮我这样做吗?不用担心多余的空间。由于网站不接受我的问题,我已经修改了:)
1573 次
1 回答
1
I'm not sure if this is what you're asking, but this was working for me:
final WorldWindowGLCanvas aCanvas = new WorldWindowGLCanvas();
aCanvas.setModel(new BasicModel());
aCanvas.getInputHandler().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent pE) {
Position aCurrentPosition = aCanvas.getCurrentPosition();
//Or whatever work:
if(aCurrentPosition != null) {
System.out.println("Current Pos= " + aCurrentPosition);
} else {
System.out.println("Current Pos is null!");
}
}
});
I added the null check to see if it would ever get null and it did not. The assumption this code is making is that a mouse click will re-center the globe to that position. Calling the aCanvas.getCurrentPosition() should return the center globe. If the canvas is not rendered or isn't visible, then this method would return null.
于 2013-12-28T15:30:32.330 回答