解决方案 »

  1.   

    把你TestRandom类里面的Random rd=new Random(); 改成Random rd=new Random(100);就可以了,这样每次随机的数是一样的。 
      

  2.   

     test(int length) 这个方法的作用是生成一个随机数并返回吧?
    调用了两次那就是两个随机数了。public void actionPerformed(ActionEvent event) {
    TestRandom trd=new TestRandom();
    String password=this,trd.test(x);
    if(event.getSource()==btnpo){
    JOptionPane.showMessageDialog(password);}
    if(event.getSource()== btnLogin)
    {
    if(txtPwd.getText().equals("")) 
    {
    JOptionPane.showMessageDialog(this,"请输入口令");
    return; 
    }
    if(txtPwd.getText().equals(password)){
    JOptionPane.showMessageDialog(this,"合法用户!");
    return;
    }else{
    JOptionPane.showMessageDialog(this,"非法用户!");
    }}
    改成这样。