为什么MosueInputListener中的方法“ mouseMoved”什么都不做?在用户按下组件后,我想获得他移动的点。但是mouseMoved只会对MouseMotionListener起作用。
这就是我想要做的。如果用户按下,我想获取他移动鼠标的位置。另一种方法是使用addMouseListener(new MoiseListener()...和addMouseMotionListener(new MouseMotionListener ...)构建两个本地类,在那里方法mouseMoved可以工作,但是我不能使用布尔值来证明用户是否按下了鼠标。 / p>
this.addMouseListener(new MouseInputListener()
{
boolean mousePressed = false;
@Override
public void mouseClicked (MouseEvent e)
{
}
@Override
public void mousePressed (MouseEvent e)
{
mousePressed = true;
}
@Override
public void mouseReleased (MouseEvent e)
{
}
@Override
public void mouseEntered (MouseEvent e)
{
}
@Override
public void mouseExited (MouseEvent e)
{
}
@Override
public void mouseDragged (MouseEvent e)
{
}
@Override
public void mouseMoved (MouseEvent e)
{
if (mousePressed)
{
//Some Code like
System.out.println(e.getPoint());
}
}
});