can't get my coordinates graphics2D mouseclick java

后端 未结 3 1485
情书的邮戳
情书的邮戳 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:48

    I found these:

    • http://www.javalobby.org/java/forums/t19387.html
    • http://www.java.net/node/685054

    Don't know if they will help or not.

    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2021-01-26 22:52

    It sounds like you need both a forward and inverse transform to translate between the two co-ordinate systems. In this example, the scaling equations are explicit; in this alternate approach, a second AffineTransform is used.

    0 讨论(0)
提交回复
热议问题