开发者

Swing mouse drag identification problem?

How do I identify mouse dragged in downward di开发者_StackOverflow中文版rection? Suppose I dragged down, I need code such as this:

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

What code should i put when mouse dragged down?


You can use a MouseAdapter and implement mouseDragged(MouseEvent e).

You have to check the coodrinates using e.getPoint() or e.getY() and compare with the previous event to get the direction.

You can detect if the mouse is dragged upwards or downwards with code similar to this:

if(e.getY() > previousY) {
  // drags downwards
} else if (e.getY() < preiousY) {
  // drags upwards
}
previousY = e.getY();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜