请问控制台输入时怎样将回显字符设为星号 请问控制台输入时怎样将回显字符设为星号? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class aaa{ public static void main(String[] args){ System.out.println((char)Integer.parseInt(args[0])); }}java aaa 42输入对应的ASCII码值 From: http://www.java2000.net/viewthread.jsp?tid=2115注意,此为模拟程序,达不到JPasswordField的真实效果,它通过每秒1000次,不断地清除当前字符,并回显星号来实现 另:请不要在Eclipse等环境运行,必须到cmd命令行里面才有效果。import java.io.*;class PasswordMasking { public static void main(String argv[]) { String password = PasswordField.readPassword("Enter password: "); System.out.println("The password entered is: " + password); }}class PasswordField { /** * @param prompt The prompt to display to the user * @return The password as entered by the user */ public static String readPassword(String prompt) { EraserThread et = new EraserThread(prompt); Thread mask = new Thread(et); mask.start(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String password = ""; try { password = in.readLine(); } catch (IOException ioe) { ioe.printStackTrace(); } // stop masking et.stopMasking(); // return the password entered by the user return password; }}class EraserThread implements Runnable { private boolean stop; /** * @param The prompt displayed to the user */ public EraserThread(String prompt) { System.out.print(prompt); } /** * Begin masking...display asterisks (*) */ public void run() { stop = true; while (stop) { System.out.print("\010*"); try { Thread.currentThread().sleep(1); } catch (InterruptedException ie) { ie.printStackTrace(); } } } /** * Instruct the thread to stop masking */ public void stopMasking() { this.stop = false; }} char getEchoChar(): 获取用户定义的文本区回显字符; 用这个TextField 方法不就可以拉吗?TextField tf = new TextField();tf.getEchoChar('*'); LZ看看! 应该有帮助http://topic.csdn.net/t/20040511/23/3056639.html http://topic.csdn.net/t/20040511/23/3056639.html 打不开阿 线程问题,求大虾讲解 求Java版的桌面弹窗代码 hibernate3 的问题。 JTable 的拖拉时的滚动条问题?急!急!急! 关于java -Xms -Xmx的问题 java 和 asp 有什么区别? 请问如何将一个String 转成二进制并打印出来? tomcat设置问题 如何去掉AWT 中的 TextArea 和TextField 的 边框(Border) ? 有没有jbuilder5的操作说明?最好带实例的,我想好好学但没有书 问一个关于异常的问题 JAVA新手的困惑~~~~
public class aaa{
public static void main(String[] args){
System.out.println((char)Integer.parseInt(args[0]));
}
}
java aaa 42输入对应的ASCII码值
另:请不要在Eclipse等环境运行,必须到cmd命令行里面才有效果。
import java.io.*;class PasswordMasking {
public static void main(String argv[]) {
String password = PasswordField.readPassword("Enter password: ");
System.out.println("The password entered is: " + password);
}
}class PasswordField {
/**
* @param prompt The prompt to display to the user
* @return The password as entered by the user
*/
public static String readPassword(String prompt) {
EraserThread et = new EraserThread(prompt);
Thread mask = new Thread(et);
mask.start();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String password = "";
try {
password = in.readLine();
} catch (IOException ioe) {
ioe.printStackTrace();
}
// stop masking
et.stopMasking();
// return the password entered by the user
return password;
}
}class EraserThread implements Runnable {
private boolean stop; /**
* @param The prompt displayed to the user
*/
public EraserThread(String prompt) {
System.out.print(prompt);
} /**
* Begin masking...display asterisks (*)
*/
public void run() {
stop = true;
while (stop) {
System.out.print("\010*");
try {
Thread.currentThread().sleep(1);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
} /**
* Instruct the thread to stop masking
*/
public void stopMasking() {
this.stop = false;
}
}
用这个TextField 方法不就可以拉吗?TextField tf = new TextField();
tf.getEchoChar('*');
http://topic.csdn.net/t/20040511/23/3056639.html
打不开阿