请问控制台输入时怎样将回显字符设为星号?

解决方案 »

  1.   


    public class aaa{
    public static void main(String[] args){
    System.out.println((char)Integer.parseInt(args[0]));
    }
    }
    java aaa 42输入对应的ASCII码值
      

  2.   

    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;
      }
    }
      

  3.   

    char getEchoChar(): 获取用户定义的文本区回显字符; 
    用这个TextField 方法不就可以拉吗?TextField tf = new TextField();
    tf.getEchoChar('*');
      

  4.   

    LZ看看! 应该有帮助
    http://topic.csdn.net/t/20040511/23/3056639.html
      

  5.   

    http://topic.csdn.net/t/20040511/23/3056639.html 
    打不开阿