Search code examples
javamousemotionlistener

Making the mouse coordinates take the center of a frame as Origin-Java


How can I make MouseMotionListener reads (0,0) in the center of a frame instead of the default top left position?


Solution

  • You don't. Instead you translate the Point returned in your program's model.

    Create a method, Point convert(Point p) where you translate (and scale if need be), the Point on the view that the MouseMotionListener returns, to give the Point in the program's model.