Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在SWT应用程序中加载屏幕/对话框_Java_Multithreading_Swt - Fatal编程技术网

Java 在SWT应用程序中加载屏幕/对话框

Java 在SWT应用程序中加载屏幕/对话框,java,multithreading,swt,Java,Multithreading,Swt,我正在编写一个从数据库加载数据的应用程序。。在那个时候,GUI出现了问题,因为我只使用了一个线程 因此,我想通过添加一个加载对话框来改进我的应用程序,比如(我知道它的PHP;):p) 但我对线程问题不太熟悉 到目前为止,加载对话框中的我的代码: import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; impo

我正在编写一个从数据库加载数据的应用程序。。在那个时候,GUI出现了问题,因为我只使用了一个线程

因此,我想通过添加一个加载对话框来改进我的应用程序,比如(我知道它的PHP;):p)

但我对线程问题不太熟悉

到目前为止,加载对话框中的我的代码:

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Dialog;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.ProgressBar;
    import org.eclipse.swt.widgets.Shell;

    public class LoadingView extends Dialog {

        protected Object result;
        protected Shell shell;
        private Label labelText;

        /**
         * Create the dialog.
         * 
         * @param parent
         * @param style
         */
        public LoadingView(Shell parent, int style) {
            super(parent, style);
        }

        public void upadteLabel(String neuerText) {

            labelText.setText(neuerText);
        }

        public void kill() {

            shell.dispose();
        }

        /**
         * Open the dialog.
         * 
         * @return the result
         */
        public Object open() {
            createContents();
            shell.open();
            shell.layout();
            Display display = getParent().getDisplay();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
            return result;
        }

        /**
         * Create contents of the dialog.
         */
        private void createContents() {
            shell = new Shell(getParent(), getStyle());
            shell.setSize(349, 80);
            shell.setText(getText());

            ProgressBar progressBar = new ProgressBar(shell, SWT.INDETERMINATE);
            progressBar.setBounds(10, 10, 323, 17);

            labelText = new Label(shell, SWT.NONE);
            labelText.setBounds(10, 33, 323, 15);

        }
如何从“主应用程序”/“主线程”调用此对话框

我有我的主应用程序的GUI循环。在这个线程中,我必须从LoadingDialog调用GUI循环,对吗?在一个额外的线程中,我调用了数据库加载方法an,从中我更新了对话框文本(比如“加载XYZ”,然后是“加载XYZ2”…)

也许你知道一个很好的例子。。因为我找不到完全一样的东西…:/

谢谢你的帮助

Display.getDefault().syncExec(new Runnable() {