can't get my coordinates graphics2D mouseclick java

后端 未结 3 1538
情书的邮戳
情书的邮戳 2021-01-26 22:41

I got an extended JLabel class where I draw my Map using the code below : the new AffineTransform() is the identity to left my image as it is (0,0,w,h)

3条回答
  •  醉酒成梦
    2021-01-26 22:49

    Its not so hard ;-)

    1. When you repaint the Component save the AffineTransform after the transforming with g2.getTransform()

    2. Then call the function invert() on it

    3. In the mouseClicked() event us the following code:

      Point2D p= trans.transform(new Point2D.Double(evt.getX(), evt.getY()), null);
      System.out.println("click x="+p.getX()+" y="+p.getY());
      

    Thats it!

提交回复
热议问题