Question

I have mouseMotionListener in my jpanel code.

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

Was it helpful?

Solution

Use

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

in your listener.

Hope this helps.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top