Computer Science Canada Reading characters without having them show up on the screen? |
Author: | alexsb92 [ Sat Mar 27, 2010 7:24 pm ] |
Post subject: | Reading characters without having them show up on the screen? |
Hey guys, I am trying to read a character in Java without having it show up on the screen. It is possible with the hsa class, but i absolutely hate ready to program, and I do not want to use it. Is there any way to do that with Standard Java libraries? Basically I am looking for the Java equivalent of readkey that is found in Pascal. Thanks |
Author: | TerranceN [ Sat Mar 27, 2010 8:55 pm ] | ||
Post subject: | Re: Reading characters without having them show up on the screen? | ||
I don't know what readkey is in Pascal so I hope this is what you mean. Look into the KeyListener and KeyEvent classes. If you implement KeyListener in your class then you can use the KeyTyped method to get the KeyEvent. Also, in order for it to get key events you need to add it to a Component using addKeyListener. Here is an example:
Hope that helps. |
Author: | TheGuardian001 [ Sat Mar 27, 2010 9:29 pm ] | ||
Post subject: | Re: Reading characters without having them show up on the screen? | ||
If you don't want a GUI one, I believe java.io.Console has a readPassword method which doesn't echo. It returns an array of characters though, so you'd have to put it in a string yourself. to set it as the default console input, use
|