我有以下代码在后台执行登录过程:
private class LoginThread extends SwingWorker<Boolean, Object> {
private Controller controller;
private String userName;
private String password;
public LoginThread(Controller controller, String userName, String password) {
this.controller = controller;
this.userName = userName;
this.password = password;
}
@Override
protected Boolean doInBackground() throws Exception {
status.setText("Try to log in user " + userName + "...");
return controller.login(userName, password);
}
@Override
protected void done() {
try {
if (get()) {
controller.loginDone();
} else {
showErrorMessage("Can't login user " + userName + ".");
}
} catch (Exception ignore) {
showErrorMessage("Can't login user " + userName + ".");
}
}
}
我无法在API中找到SwingWorker的第二个类型参数的解释。第一种类型可能是doInBackground方法返回的类型,但第二种类型是什么?
答案 0 :(得分:10)
正如SwingWorker文档中所述:
java.lang.Object javax.swing.SwingWorker<T,V> Type Parameters: T - the result type returned by this SwingWorker's doInBackground and get methods V - the type used for carrying out intermediate results by this SwingWorker's publish and process methods