1
\$\begingroup\$

I have a simple mouse manager class: https://imgur.com/MuUhh73

Whenever any of the mouse buttons are pressed the mouse position does not update when calling getMouseX() or getMouseY() on the mouse manager object via a basic handler that gets passed everywhere.

Is the problem in my implementation or is it a bug in general?

\$\endgroup\$
2
\$\begingroup\$

The problem is with your implementation.

Change your button handling code to something like :

if (e.getButton() == MouseEvent.Button1) {
    leftpressed = true;
    mouseX = e.getX();
    mouseY = e.getY();
}

Basically you want to update the stored mouse position on all mouse events.

\$\endgroup\$
  • \$\begingroup\$ Thanks! Works perfectly! Just needed to update the mouse position on mouseDragged(MouseEvent e) function in the mouse manager class. \$\endgroup\$ – Kerdo Feb 28 '18 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.