Question

I have mouseMotionListener in my jpanel code.

But how can I know if the mouse dragged to left or right inside the jpanel?

Était-ce utile?

La solution

Use

if (currentX > previousX) {
    // Right
} else {
    // Left
}
previousX = currentX;

in your listener.

Hope this helps.

Autres conseils

In the event callback: store the mouse-(x-)position, in the next callback calculate the difference to the previous position (and store the position again); depending on the sign(um) you can determine whether it was a left or right drag.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top