如何检测鼠标移动方向并在控制台中打印或在JTextField中设置文本,例如:在mouseMoved事件的JPanel中“鼠标向左移动”?
编辑:我创建了正确的代码:
private int oldX = 0;
@Override
public void mouseMoved(MouseEvent e)
{
if(oldX > e.getX())
{
System.out.println("Mouse moved left");
}
if(oldX < e.getX())
{
System.out.println("Mouse moved right");
}
oldX = e.getX();
}