用正则表达式是明白了,但是用一个什么样的方式的listener呢最好能帮忙写一下源代码,我最近刚刚接触swing,谢谢了

解决方案 »

  1.   

      我认为你没有必要设置listener,你获取用户填写的信息后,做一个if判断,然后用JPanel进行提示就可以了
      

  2.   

    String user;
      String password;
      user=this.user.getText();
     password=this.password.getText(); 
     if(user.length()==0){
     System.out.println("用户名不能为空");
     this.user.grabFocus();
     return;
      }
      if(password.length()==0){
      System.out.println("密码不能为空");
      this.password.grabFocus();
      return;
      }这个类型就可以了
      

  3.   

    DocumentListener可以实现每次按键的监听,并且由自己决定当前按键的字符是否要插入到文本中显示,键盘监听做不到这一点