1

I am trying to write a program which will allow two players to play "a guess word" game as part of my learning curve in Java. When prompted, player 1 types in a word but the screen displays an asterisk * for each letter in the word. Simply player 1 types a word but the word should be displayed in asterisks rather than characters. I seem to have problem getting this one right.

Is there any method(s) in Stream Buffer or Scanner class that'll allow me to do that above.

thank you.

Sinan
  • 443
  • 1
  • 10
  • 20

1 Answers1

3

The intuition that you should intercept input, save original data, and show it masked in the console. You can achieve that by separate thread working on it.

Use this reference http://java.sun.com/developer/technicalArticles/Security/pwordmask/

Magic happens in EraserThread class.

mishadoff
  • 10,583
  • 2
  • 32
  • 54
  • Hi, Thank you for your comment. could you please elaborate more into saving the original data? what do you mean by it and how can I achieve it ? can I use an array to do so!! – Sinan May 19 '12 at 19:16
  • Sure, you can save it in array, string and so on. But in link posted in answer all this implemented and use `PasswordField.readPassword` method which returns string. – mishadoff May 19 '12 at 19:41
  • @mishadoff The link is dead so this answer is useless. Please update it to have all necessary information. – Aleksandr Kravets Oct 13 '16 at 09:59