нужна помощь по теме SWT, Threads.
Я хочу перед стартом GUI выполнить особые конфигурации. Их я выполняю в Progressbar:
package main_gui.gui; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Shell; import main.StartThread; public class StartProgram { private static Display display; protected Shell shell; public static void main(String args[]) { display = Display.getDefault(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { try { StartProgram window = new StartProgram(); window.open(); } catch (Exception e) { e.printStackTrace(); } } }); } protected void createContents() { shell = new Shell(display, SWT.TITLE | SWT.PRIMARY_MODAL); shell.setSize(491, 197); Label status = new Label(shell, SWT.NULL); status.setAlignment(SWT.CENTER); status.setBounds(38, 77, 399, 71); /** take the primary monitor */ Monitor primary = display.getPrimaryMonitor(); /** get the size of the screen */ Rectangle bounds = primary.getBounds(); /** get the size of the window */ Rectangle rect = shell.getBounds(); /** calculate the centre */ int x = bounds.x + (bounds.width - rect.width) / 2; int y = bounds.y + (bounds.height - rect.height) / 2; /** set the new location */ shell.setLocation(x, y); ProgressBar progressBar = new ProgressBar(shell, SWT.NONE); progressBar.setMaximum(0); progressBar.setBounds(38, 49, 399, 17); new StartThread(shell, display, progressBar, status).start(); } public void open() { createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }
Thread, для выполнения конфигурации для Progressbar:
package main; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Shell; import main_gui.gui.MainGui; import processlistener.ProcessListener.Processes; public class StartThread extends Thread { private Shell shell; private Display display; private ProgressBar progressBar; private Label labelInfo; public StartThread(Shell shell, Display display, ProgressBar progressBar, Label labelInfo) { this.shell = shell; this.display = display; this.progressBar = progressBar; this.labelInfo = labelInfo; } @Override public void run() { if (display.isDisposed()) { return; } try { System.out.println("Konfiguration"); Thread.sleep(500); } catch (Exception e) { System.out.println(e); } } /** * * @param statusText */ private void setFehler(String fehler) { display.asyncExec(new Runnable() { @Override public void run() { labelInfo.setText(fehler); } }); } /** * */ private void closeProgressGUI() { display.asyncExec(new Runnable() { @Override public void run() { shell.close(); } }); } /** * */ private void startMainGUI() { display.asyncExec(new Runnable() { @Override public void run() { MainGui main = new MainGui(); main.open(); // shell.dispose(); } }); } }
Моя проблема заключается в том что я не знаю как определить что Thread готов, закрыть progressbar и открыть мою последующую маску. Очень прошу помощи, я не сильна по теме Threads и все мои попытки приводят к Exceptions.
Прошу хотя бы какие то советы.Спасибо