线条没有在我点击的地方画出来? [英] Lines aren't drawing exactly where I clicked?

查看:26
本文介绍了线条没有在我点击的地方画出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是一个容易回答的问题.我通过以下方式获取鼠标位置:

I'm hoping this is an easy question to answer. I am getting the mouse location via:

one1 = e.getX();
one2 = e.getY();

我这样做了两次以获得线的起点和终点,但是当绘制线时,坐标有点偏离.我没有调整窗口大小或其他任何东西?

And I do this twice to get both the start and the end of the line, but when the line is drawn the coordinates are a good bit off. I haven't resized the window or anything?

g2d.drawLine(one1, one2, two1, two2);

在画线之前我需要检查或调整一些额外的东西吗?

Is there something extra I need to check or adjust before drawing the line?

推荐答案

现在搞定了,指出的注释是父框架或实际画布上的侦听器.这是问题的一部分,但也在改变

Got this sorted now, the comment that pointed out was the listener on the parent frame or the actual canvas. This was part of the problem, but also changing

one1 = e.getX();
one2 = e.getY();

到:

one1 = (int)e.getX();
one2 = (int)e.getY();

我真的不知道为什么这会有所作为,但确实如此.

I don't really know why that makes a difference but it did.

这篇关于线条没有在我点击的地方画出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆