使用 Canvas 制作游戏菜单?

发布于 2024-12-25 21:35:16 字数 134 浏览 1 评论 0原文

我已经熟悉 JButtons、JLabels 等,但我想开始制作一个非常“多彩”的游戏菜单。有没有办法使用 Canvas 来做到这一点(比如添加鼠标侦听器并在 PhotoShop 中创建一些按钮并检测鼠标是否悬停在按钮上并单击按钮),或者有更好的方法吗?

I am already familiar with JButtons, JLabels and such, but I want to start making a game a very "colorful" menu. Is there a way to do this using Canvas (like adding a mouse listener and make some buttons in PhotoShop and detect if the mouse hovers over and clicks the button), or is there a better way?

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

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

发布评论

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

评论(1

阳光下慵懒的猫 2025-01-01 21:35:16

由于您已经熟悉 JButton,您可能会发现更容易(也更实用)的是,只需扩展现有的 JButton 并修改其外观,使其看起来像图像而不是传统的灰色按钮。

除此之外,这意味着您可以免费获得所有标准按钮行为,包括特殊情况,而作为交换,您所要做的就是重写一些方法。

阅读以下问题的已接受答案,它几乎准确地解释了如何做到这一点:

用 Java 创建自定义按钮

Since you're already familiar with JButtons, you may find it easier (and more practical) simply to extend the existing JButton and modify its appearance, so that it looks like an image rather than the traditional grey button.

Amongst other things, it means you get all the standard button behaviour for free, including special cases, and in exchange all you have to do is override a couple of methods.

Have a read through the accepted answer for the following question, which explains pretty much exactly how to do that:

Creating a custom button in Java

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