围绕中心点旋转 jpanel 中的多个按钮的最佳方法是什么?

发布于 2024-10-05 17:24:36 字数 135 浏览 5 评论 0原文

我正在开发一个项目,其中我有一个带有特定兴趣点的背景图像。每个特定点都会覆盖一个自定义按钮类,这样当我单击该点时,我实际上是在单击该按钮。但是,我希望能够旋转背景图像并使按钮随图像旋转,以便自定义按钮仍然覆盖在特定点上。关于我应该如何做这件事有什么建议吗?

I am working on a project in which I have a background image with specific points of interest. Each of these specific points will have a custom button class overlaid on it so that when I click the point, I'm actually clicking the button. However, I would like to be able to rotate the background image and have the buttons rotate with the image so that the custom buttons are still overlaid on the specific points. Any tips as to how I should go about doing this?

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

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

发布评论

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

评论(1

愛上了 2024-10-12 17:24:37

您是否真的想要旋转 4 个不同的图像并将它们绕着正方形移动,但始终保持它们直立?或者您是否正在旋转单个图像,以便单击一个按钮后该单个图像位于其一侧?如果是前者,那么可以通过使用使用 BorderLayout 的容器(JPanel)轻松完成,并在 BorderLayout 的四个罗盘点处将四个带有背景图像的 JPanel 和 JButton 保存在容器 JPanel 中:BorderLayout.EAST、BorderLayout .WEST、BorderLayout.NORTH 和 BorderLayout.SOUTH(尽管 Java 专家更喜欢使用较新的常量,即 BorderLayout.PAGE_START)。然后,当按下按钮时,删除组件并重新添加,但按旋转顺序。

如果您想做后者,那么事情会变得有点棘手,因为您可能需要使用 AffineTransforms、旋转实例来旋转容器,并且您需要在鼠标按下/的点上执行相同的转换单击/释放,以便旋转的按钮收到正确的单击声。如果容器不是方形的,事情就会变得更加棘手。

Are you actually wanting to rotate 4 different images and move them around the square, but always keeping them upright? Or are you rotating a single image so that after one button click the single image is on its side? If the former, then that can be easily done by using a container (a JPanel) that uses BorderLayout, and having four JPanels with background images and JButtons held in the container JPanel at the four compass points of the BorderLayout: BorderLayout.EAST, BorderLayout.WEST, BorderLayout.NORTH, and BorderLayout.SOUTH (although Java gurus prefer you use the newer constants, i.e., BorderLayout.PAGE_START). Then when a button is pressed, remove components and re-add but in a rotated order.

If you want to do the latter, then things get a bit trickier in that you'll likely need to use AffineTransforms, rotate instance to rotate the container, and you'll need to perform the same transformation on the point of the mouse press/click/release, so that the rotated buttons receive correct clicks. If the container is not square, things get even trickier still.

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