不一定,
如果
class OuterClass{
   JPassField jpf1, jpf2;
   .....
   jpf1.addActionListener(new InnerClass1());
   jpf2.addActionListener(new InnerClass2());
   class InnerClass1 implements ActionListener{
        public void actionPerformed(ActionEvent e){
            //What is the e.getSource()? jpf1, jpf2 or something else 
            //that is not listed here?
        }
   }
   ...........
}如果你能确定触发这个内部类ActionListener的只可能是唯一一个控件时,可以完全抛开e.getSource()

解决方案 »

  1.   

    首先谢谢两位热情的回应,两位写的我不是太明白。我的意思说白了就是highlight部分写成下面的形式有什么不好:(我是过这样也可以运行成功地)
    //////////////////////////////////////////////////////////////////////////////
    else  if  (  e.getSource()  ==  password  )  {    
                           s  =  "password:  "  +  
                                   new  String(  password.getPassword()  );  
                     }  
    //////////////////////////////////////////////////////////////////////////////
      

  2.   

    喜欢怎么用就怎么用
    但我认为这样会比较好:
                   ...
                    if  (  e.getSource() instanceof  JPasswordField   )  {  
                           JPasswordField  pwd  =  
                                 (JPasswordField)  e.getSource();  
                           s  =  "password:  "  +  
                                   new  String(  pwd.getPassword()  );  
                     }