在JPanel中检测鼠标移动方向

时间:2016-02-28 18:52:00

标签: java mouse direction

如何检测鼠标移动方向并在控制台中打印或在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();
    }

0 个答案:

没有答案