Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

java - word (password) displays in asterisks - Console application

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...