Get input from keyboard with Canvas
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开发者_Python百科 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).
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!
精彩评论