mouseReleased() not being called after a mouseDragged() event?
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
}
精彩评论