Java Applet 图形大小调整

发布于 2024-10-20 07:45:21 字数 344 浏览 1 评论 0原文

所以我有一个任务,需要两个输入,男性和女性,并输出matingPairs,即两者的乘积。

除此之外,说明还要求使用这些变量之一绘制形状。

我决定为每个值画圆圈。

我首先绘制交配对,然后在原始的较大交配对圆圈上方绘制较小的男性和女性圆圈。

我遇到的问题显然是在小程序中表示图形。如果数字高于 100,则图形对于小程序来说太大。

我正在寻找一种方法,基本上让matingPairs圆圈始终填充小程序,然后让雄性和雌性动态调整,以便它们的大小相对于matingPairs圆圈大小进行缩放。我正在使用 JApplet。

非常感谢您的指导。我真的在寻找解决方案,而不是朝着正确的方向推动。

So I've got an assignment that takes two inputs, males and females, and outputs matingPairs, the product of the two.

In addition to that, the instructions ask to draw a shape using one of those variables.

I've decided to draw circles for each value.

I first draw matingPairs, followed by the smaller male and female circles on top of the original, larger matingPairs circle.

The problem I'm running in to is obviously representing the graphic in the applet. If the numbers go higher than say 100, the graphic becomes too large for the applet.

I'm looking for a way to basically have the matingPairs circle always fill the applet, then have males and females dynamically adjust so their size is scaled relative to the matingPairs circle size. I'm using JApplet.

Thank you very much for any guidance. I'm really looking for a solution, rather a push in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

完美的未来在梦里 2024-10-27 07:45:21

也许您应该提供有关如何在 Graphics 对象中绘制圆圈的更多说明。
这个想法是管理两个不同尺度的二维空间;第一个是输入数据,第二个表示绘制此类数据的可用区域。第一个可以包含任何位置的数据,例如 (5, 5)(0.2, 0.3)(1200, 3400)。关键是使用适当的变换将第一个空间的原始坐标映射到第二个空间:缩放+平移。
此变换必须在开始绘制之前计算并适用于绘制的任何点。
这个想法是将输入数据所在的矩形映射到图形中的可用区域。如果图形区域为 200x200 像素,并且数据可以从 (0, 0)(400, 400),只需将要绘制的点的坐标除以 2 。如果原始数据未以 (0, 0) 为中心,则使用翻译。

May be you should provide more instruction about how are you drawing the circles in the Graphics object.
The idea is to manage two bi-dimensional spaces with different scales; the first one is the input data and the second one represents the available area to draw such data. The first one can have data on any location, such (5, 5), (0.2, 0.3)or (1200, 3400). The key is to map the original coordinates of the first space into the second, using the proper transformation: scale + translation.
This transformation must be calculated prior to start drawing and applies to any point drawn.
The idea is to map the rectangle where input data resides to the available area in the graphics. If the graphics area is 200x200 pixels and the data could be from (0, 0) to (400, 400), just divide by 2 the coordinates of the points to draw. If the original data is not centered in (0, 0), use a translation.

吃→可爱长大的 2024-10-27 07:45:21

那么,您是否需要知道如何获取小程序画布的大小或如何相应地缩放男性/女性圆圈?

编辑:

绘制一个圆圈来填充 600x600 区域应该很容易。请记住,在调用drawOval() / fillOval() 或类似方法时,您经常指定圆的左上角以及宽度和高度(即直径)。

下一个问题是:什么代表输入(男性/女性)和输出(对)的大小、圆的面积或半径?不管是什么,应该很容易计算出输入/输出比率,然后将输出圆的固定大小与其相乘,以获得输入圆的大小。

So, do you need to know how to get the size of the applets canvas or how to scale the male/female circles accordingly?

Edit:

Drawing a circle to fill the 600x600 area should be easy. Just keep in mind that you often specify the top left corner of the circle and the width and height (i.e. the diameter) when calling drawOval() / fillOval() or similar methods.

The next question is: what does represent the size of the input (males/females) and output (pairs), the area or the radius of the circles? Whatever it is, it should be easy to calculate the input/output ratio and then multiply the fixed size of the output circle with it in order to get the size of the input circle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文