使用 Canvas 从键盘获取输入

发布于 2024-10-07 20:57:39 字数 376 浏览 2 评论 0原文

我想创建一个 Upwords 桌面应用程序,所以我认为游戏桌应该显示为帆布。在游戏开始时,我想要求用户对将要玩的玩家做出一些输入,但我没有任何想法。你能帮我一下吗?

另外,如果有比使用画布更好的实现想法,我将很高兴听到您的声音。

提前致谢。


不,这不是我的第一个 GUI 应用程序,但我的经验很少。我认为制作自己的类是个好主意,但我不确定,因为我想使用 GUI 构建器(截止日期问题),并且在过去我遇到了一些问题对于这一点,我会尝试一下。对于输入,我考虑了 JDialog,但我必须模拟移动环境,因此提示必须显示在“屏幕”(我们案例中的画布)上。

I want to create an Upwords application for desktop and so I think that the game table should be displayed as canvas. In the beginning of the game I want to ask the user to make some input about the players that will play, but I don't have any ideas. Could you please help me on that?

Also, if there are better implementation ideas than to use canvas, I would be grateful to hear you.

Thanks in advance.


No it's not my first GUI application but I have very little experience.I think it's a good idea to make my own class but I was't sure because I want to use GUI builder(deadline issues) and in the past I had some problems on this.I will try it.For the input I thought about JDialog but I have to simulate a mobile environment so the prompt must be shown on the "screen"(the canvas on our case).

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

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

发布评论

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

评论(1

可是我不能没有你 2024-10-14 20:57:39

你有一个相当广泛的问题,我猜这是你的第一个(或第一个)java 图形程序。我强烈建议使用 Swing,或者任何其他图形库,而不是使用 AWT 组件(如 Canvas)。我首先查看 javax.swing 的文档。 JFrame。您可能最终会创建一个自定义组件(扩展 JComponent?)并重写其 PaintComponent() 方法以提供“游戏桌”的自定义图形。

至于游戏开始时的用户输入,您可能需要查看一个对话框。查看 javax.swing.JOptionPane 它可以创建各种简单的对话框来收集用户输入,自动处理键盘输入。

有很多 java Swing 'Hello World' 类型的程序可以帮助您展示如何创建基本的 Swing 应用程序。 Java 教程 是一个很好的起点。

祝你好运!

You have a pretty broad question, and I'm guessing this is your first (or one of your first) graphical programs in java. Instead of using AWT components (like Canvas), I would strongly, strongly recommend using Swing, or really, any other graphical library. I would start by looking at the documentation for javax.swing.JFrame. You will probably end up creating a custom component (extending JComponent?) and overriding its paintComponent() method to provide the custom graphics of your 'game table'.

As far as user input at the start of your game, you may want to look at a dialog box. Look at the documentation for javax.swing.JOptionPane which can create a wide variety of simple dialog boxes for gathering user input, taking care of the keyboard input automagically.

There are plenty of java Swing 'Hello World' type programs out there that can help show you how to create a basic Swing app. The Java Tutorials is a good place to start.

Good luck!

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