fillRect() 中的负数
我使用负数让 fillRect()
走相反的方向。它在我的计算机上运行良好,但我的朋友看不到它正常运行。我该怎么办?
page.fillRect (12, 12, -5, 10);
I am using a negative number to have fillRect()
go the opposite way. It works well on my computer, but my friends cannot see it working properly. What do I do?
page.fillRect (12, 12, -5, 10);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对此有两种观点。
一是任何具有负尺寸的多边形都是无意义的,不应该被渲染 - 你是什么意思它是 -10 像素宽?
另一个是负尺寸只是简单地反转该尺寸轴上的多边形。
大多数绘画系统都应用后一种逻辑。我用Java绘画的经验一直都是这样,尽管我不会经常有负面的维度,所以我的经验可能没有多大意义。
至于你能做什么:
就我个人而言,如果可能的话,我更愿意需要更新的 JVM。
否则我推荐的代码是:
另外,请注意,您将需要类似的其他绘图操作。
最后,我会怀疑这一切中的另一个错误,因为这种行为非常令人惊讶 - 我会将所有内容简化为一个最小的测试程序,在包装大量绘画基元之前进行调试输出和验证。
There are two schools of thought on this.
One is that any polygon with a negative dimension is nonsensical and should not be rendered - what do you mean it's -10 pixels wide??
The other is that a negative dimension simply inverts the polygon on that dimension's axis.
Most painting systems apply the latter logic. My experience in painting with Java has always been this, though I would not often have had negative dimensions, so my experience might not count for much.
As to what you can do:
Personally, I would prefer to require a newer JVM, if possible.
Otherwise my recommended code would be:
Also, note that you'll need similar for other drawing operations.
Lastly, I would be suspicious of another mistake in all this, since the behavior is very surprising - I would simplify everything down to a minimal test program, with debug output and verify before wrapping a crap load of painting primitives.
我的猜测是您和您的朋友正在使用 2 个不同版本的 Java。你支持 fillrect 为负值,而你朋友则不支持。 (甚至是 sdk 与 jre)。
这表明您应该以不同的方式编写它,以使您的小程序在所有版本上运行。
为什么不简单地移动你的 x 为 -5 呢?
如果你想以更简洁的方式做到这一点
My guess is that you and your freind are using 2 different versions of Java. your supports fillrect with a negative value and your freind's doesn't. (or even sdk vs jre).
what that shows is that you should write this a different way to have your applet run on all versions.
why not simply move your x of -5 ?
if you want to do it in a more neat way
只是指出劳伦斯代码中的一个小问题,当您向上拖动给出错误高度值的矩形时出现该问题。
问题出在行中
必须是 y 而不是 x :
,总共
Just indicating a small issue in Lawrence code that appear when you drag up the rect which give wrong height value.
The problem is in the row
and it has to be y not x
in total: