简体   繁体   English

Java C / S应用程序预加载器(如Ajax)

[英]Java C/S Application preloader (like Ajax)

I would like to implement a "wait" preloading message in a Java desktop application (I use Swing), like the preloaders the Ajax/Flash developers use in web applications. 我想在Java桌面应用程序(我使用Swing)中实现“等待”预加载消息,就像Ajax / Flash开发人员在Web应用程序中使用的预加载器一样。

My application uses a client/server architecture, and there may be some delay when moving from window to window, due to the response time of the server, but the user should not be able to do anything until all the content is loaded . 我的应用程序使用客户机/服务器体系结构,由于服务器的响应时间,从一个窗口移到另一个窗口可能会有一些延迟,但是在加载所有内容之前,用户应该无法执行任何操作

What's the best practice to do this? 最佳做法是什么? I had 2 ideas, but I think there should be a better way to handle this: 我有两个想法,但我认为应该有更好的方法来解决这个问题:

1 idea) Blocking the Event Dispatcher Thread (is that even possible?) 1个想法)阻塞事件分派器线程(甚至可能吗?)

alternative idea) Hide the whole JFrame until the message exchange with the server is completed and the content is ready, showing another "wait" JFrame, but I dont really like this solution, because the main JFrame would keep flashing on/off during the user interaction 另一种想法)隐藏整个JFrame,直到与服务器的消息交换完成并且内容准备就绪为止,显示另一个“等待” JFrame,但是我不太喜欢这种解决方案,因为主JFrame在用户使用期间会不断地闪烁相互作用

EDIT: Thanks to some hints I figured it out, but I can't give the answer to anyone (nobody actually answered, i have only comments!), should i vote to delete the question? 编辑:由于一些提示我弄清楚了,但我无法将答案提供给任何人(没有人实际回答,我只有评论!),我应该投票删除问题吗?

I solved the issue using a JDialog, playing with setVisible(true/false) and denying the possibility for the user to close the dialog by pressing the X button, using setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 我使用JDialog解决了该问题,使用setVisible(true / false)并使用setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)来按下X按钮,以防止用户关闭对话框。

public class PreloaderDialog extends JDialog {              

        publicPreloaderDialog() {

                initialize();
        }

        public final void initialize() {

                JLabel waittext = new JLabel("Wait, please");    
                add(waittext);

                setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
                setModalityType(ModalityType.APPLICATION_MODAL);

                setTitle("Loading in progress");

                setLocationRelativeTo(null);
                setSize(300, 120);
        }

        public void hide() {

           setVisible(false);                               
        }

        public void show() {                                       

            setVisible(true);                               
        }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM