简体   繁体   English

在 Java 中输入而不按 Enter

[英]Input in Java without pressing enter

I want to take any input in Java without pressing the enter key.我想在不按回车键的情况下在 Java 中进行任何输入。 Actually I want to make a password input program, so that as soon as the user enter any character, I can clear the screen and replace the characters with an equal number of asterisks ("*"), like the typical password entries made anywhere in the web.其实我想做一个密码输入程序,这样只要用户输入任何字符,我就可以清除屏幕并用相同数量的星号(“*”)替换字符,就像在任何地方输入的典型密码一样网络。 Most importantly, I would like to do the same in the Java Terminal Window, not by using those applet methods.最重要的是,我想在 Java 终端窗口中做同样的事情,而不是使用那些小程序方法。 Please tell me if i would have to supply more details.请告诉我是否需要提供更多详细信息。 I am using BlueJ.我正在使用 BlueJ。

Thank you, Mayank.谢谢你,玛雅克。

You may want to have a look at the Console 's readPassword(...) methods (needs Java 6+).您可能想看看ConsolereadPassword(...)方法(需要 Java 6+)。

Or, when using Java 5 (or less), have a look at this article: Password Masking in the Java Programming Language , especially the paragraph Command-Line Input Masking .或者,在使用 Java 5(或更低版本)时,请查看这篇文章: Java 编程语言中的密码屏蔽,尤其是段落命令行输入屏蔽

这是有关如何实现所需的完整文章: http : //java.sun.com/developer/technicalArticles/Security/pwordmask/

Oracle有一个很棒的有关Key Listener的教程,它可以帮助您了解要去的地方: https : //docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM