can't get my coordinates graphics2D mouseclick java

自作多情 提交于 2019-11-29 17:27:21
trashgod

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.

MadProgrammer

I found these:

Don't know if they will help or not.

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!