摆动鼠标拖动识别问题?

Gan*_*esh 0 java mouse swing

如何识别向下拖动的鼠标?假设我拖了下来,我需要这样的代码:

int graphy = e.getY();
System.out.println("this is y axises " + graphy);
_graph._verticalScroll.setValue(graphy + _graph._headerWidth
    + _graph._verticalScroll.getValue());
Run Code Online (Sandbox Code Playgroud)

拖动鼠标时我应该放什么代码?

Jon*_*nas 6

您可以使用MouseAdapter并实现mouseDragged(MouseEvent e).

您必须使用e.getPoint()或检查coodrinates e.getY()并与之前的事件进行比较以获得方向.

您可以检测鼠标是向上还是向下拖动,代码类似于:

if(e.getY() > previousY) {
  // drags downwards
} else if (e.getY() < preiousY) {
  // drags upwards
}
previousY = e.getY();
Run Code Online (Sandbox Code Playgroud)