定义一个PopupAuthenticator 的类,它是Authenticator类的子类,
在PopupAuthenticator类中定义了一个getPasswordAuthentication()的方法,返回一个PasswordAuthentication类型的对象。
最后是声明一个Authenticator类型 的auth引用,指向PopupAuthenticator类型的实例。
不知道我的理解对不对?
在PopupAuthenticator类中定义了一个getPasswordAuthentication()的方法,返回一个PasswordAuthentication类型的对象。
最后是声明一个Authenticator类型 的auth引用,指向PopupAuthenticator类型的实例。
不知道我的理解对不对?
class PopupAuthenticator extends Authenticator{
//新增getPasswordAuthentication方法,返回PasswordAuthentication类型数据,PasswordAuthentication类应该在前面已经有定义的
public PasswordAuthentication getPasswordAuthentication()
{
String username,password;
username="123";
password="123";
return new PasswordAuthentication(username,password);
}
}
........
//实例化类
Authenticator auth=new PopuAuthenticator();
//然后才能调用类的方法和属性,如
PasswordAuthentication pa = auth.getPasswordAuthentication();