SwingWorker 中的类型参数是什么?

发布于 2024-12-20 16:28:18 字数 1155 浏览 0 评论 0原文

我有以下代码在后台执行登录过程:

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 方法返回的类型,但是第二种类型是什么?

I have the following code to do a login process in the background:

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 + ".");
            }
        }

    }

I can´t find in the API an explanation what the second type parameter of SwingWorker is. The first type is probably the type that is returned by the doInBackground method, but what is the second type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2024-12-27 16:28:18

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

As stated on SwingWorker docs:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文