Computer Science Canada Input from keyboard? |
Author: | Unicornzrcool [ Wed Apr 15, 2009 4:25 pm ] |
Post subject: | Input from keyboard? |
*For Ready To Program Java* (I know it sucks but we have to use it in our school >.<) Ok, I'm making a menu where the user presses any key to move to the first page, how would you make it so that instead of having to write the line and press enter, it will just go once you press the key? Thanks! ![]() |
Author: | Unicornzrcool [ Thu Apr 16, 2009 7:12 am ] |
Post subject: | Re: Input from keyboard? |
anyone..? |
Author: | SJ [ Thu Apr 16, 2009 7:42 pm ] | ||||
Post subject: | Re: Input from keyboard? | ||||
haha i rbmr stuggling with this when i first started java
note though, it's better practice to add "throws IOException" at the end of the method containing the read and get rid of the try catch block. Mod Edit: Remember to use syntax tags! Thanks ![]()
|
Author: | Unicornzrcool [ Fri Apr 17, 2009 12:32 am ] | ||||||
Post subject: | RE:Input from keyboard? | ||||||
Although I'm not sure i did it right, it doesn't seem to be working. What I did was put the import statement where the others were:
and put the other code where right after it says press any key to continue:
And what happens is when I go to the page where it says press any key, it opens a blank console window. Am I putting the code in wrong? Mod Edit: Remember to use syntax tags! Thanks ![]()
|
Author: | SJ [ Fri Apr 17, 2009 7:01 am ] | ||
Post subject: | Re: Input from keyboard? | ||
you are using the custom builtin console (the c) in the hsa package for "Ready to Program" and I gave you the code for a standard java System console. the blank window you saw is the System console. in your case, you can just use
|
Author: | HellblazerX [ Fri Apr 17, 2009 9:42 am ] |
Post subject: | Re: Input from keyboard? |
Since you want a keystroke to turn the page rather than the user inputting in something and pressing enter, you'll probably want to take a took at KeyListeners. Here's a tutorial for it. However, I'm not sure if KeyListeners will work with hsa.Console classes, as I've never used them myself. |
Author: | Unicornzrcool [ Fri Apr 17, 2009 12:28 pm ] |
Post subject: | RE:Input from keyboard? |
Gah, I cant believe I've been looking around for days for such a small piece of code =P Thank you so much guys! |