开发者

mouseReleased() not being called after a mouseDragged() event?

开发者 https://www.devze.com 2023-03-08 13:49 出处:网络
Should a mouseReleased() event be called when the mouse 开发者_运维知识库is released after a mouse is dragged?

Should a mouseReleased() event be called when the mouse 开发者_运维知识库is released after a mouse is dragged?

I need mouseReleased() to be called to reset some variables used in mouseDragged(), but it never seems to be called.


Check the Oracle tutorial for a simple method to implement both listeners as Paŭlo asks in his comments

Basically (modified from the link above):

//where initialization occurs:
MyListener myListener = new MyListener();
addMouseListener(myListener);
addMouseMotionListener(myListener);

private class MyListener extends MouseInputAdapter {
  public void mousePressed(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    // you may not need this method
  }

  public void mouseDragged(MouseEvent e) {
    // do your code
  }

  public void mouseReleased(MouseEvent e) {
    // reset your variables
  }
0

精彩评论

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