比如双击进入ms word的时候,屏幕上先出现那张Office2007的标志图,等程序初始化完成之后才进入程序界面,如何用SWT做出这种效果?

解决方案 »

  1.   

    进入主程序后,先开一个新线程,带开一个Frame,设置Frame外观,然后显示logo图片,然后就接听消息,阻塞,
    主程序继续运行,完成了大量的初始化准备工作之后,发一个消息给阻塞的进程,告诉他可以结束了,
    然后就可以setVisiable了,
      

  2.   

    public class SplashScreen extends Shell { private ProgressBar loadingbar;
    /**
     * Create the shell
     * @param display
     */
    public SplashScreen(Display display) {
    super(display, SWT.ON_TOP);
    createContents();
    } /**
     * Create contents of the window
     */
    protected void createContents() {
    final FormLayout layout = new FormLayout();
    this.setLayout(layout);

    loadingbar = new ProgressBar(this, SWT.NONE);
    final FormData progressData = new FormData();
    progressData.left = new FormAttachment(0, 0);
        progressData.right = new FormAttachment(100, 0);
        progressData.bottom = new FormAttachment(100, 0);
        loadingbar.setLayoutData(progressData);
        
        final Label imageLabel = new Label(this, SWT.NONE);
    imageLabel.setImage(ImageHolder.getImage(ImageHolder.IMAGE_SPLASH));
    final FormData labelData = new FormData();
        labelData.right = new FormAttachment(100, 0);
        labelData.bottom = new FormAttachment(100, 0);
        imageLabel.setLayoutData(labelData);
    } @Override
    protected void checkSubclass() {
    // Disable the check that prevents subclassing of SWT components
    }

    public void closeAll (){
    ImageHolder.getInstance().dispose();
    }

    /**
     * 
     * @return ProgressBar
     */
    public ProgressBar getLoadingbar() {
    return loadingbar;
    } public void setLoadingBar (int maximum){
    loadingbar.setMaximum(maximum);
    }
    }public class TestSplash{
    public static void main(String args[]) {
    try {
    final Display display = Display.getDefault();
    final SplashScreen splash = new SplashScreen(display);
    splash.setLoadingBar(15);
    splash.pack();
    splash.open();
    splash.getDisplay().asyncExec(new Runnable(){ public void run() {
    for (int i = 0; i < 15; i++){
    splash.getLoadingbar().setSelection(i);
    try {
    Thread.sleep(300);
    } catch (Exception e) {
    }
    }
    splash.close();
    splash.closeAll();
    }
    });
    while (!splash.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }这样就ok了
      

  3.   

    public static void main(String[] args) {
    final Display display = new Display();
    final int[] count = new int[] { 1 };
    final Image image = new Image(display, 400, 300);
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    gc.fillRectangle(image.getBounds());
    gc.drawText("Splash Screen", 10, 10);
    gc.dispose();
    final Shell splash = new Shell(SWT.ON_TOP);
    final ProgressBar bar = new ProgressBar(splash, SWT.NONE);
    bar.setMaximum(count[0]);
    Label label = new Label(splash, SWT.NONE);
    label.setImage(image);
    FormLayout layout = new FormLayout();
    splash.setLayout(layout);
    FormData labelData = new FormData();
    labelData.right = new FormAttachment(100, 0);
    labelData.bottom = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    FormData progressData = new FormData();
    progressData.left = new FormAttachment(0, 5);
    progressData.right = new FormAttachment(100, -5);
    progressData.bottom = new FormAttachment(100, -5);
    bar.setLayoutData(progressData);
    splash.pack();
    Rectangle splashRect = splash.getBounds();
    Rectangle displayRect = display.getBounds();
    int x = (displayRect.width - splashRect.width) / 2;
    int y = (displayRect.height - splashRect.height) / 2;
    splash.setLocation(x, y);
    splash.open();
    display.asyncExec(new Runnable() {
    public void run() {
    Shell[] shells = new Shell[count[0]];
    for (int i = 0; i < count[0]; i++) {
    shells[i] = new Shell(display);
    shells[i].setSize(300, 300);
    shells[i].addListener(SWT.Close, new Listener() {
    public void handleEvent(Event e) {
    --count[0];
    }
    });
    bar.setSelection(i + 1);
    try {
    Thread.sleep(1000);
    } catch (Throwable e) {
    }
    }
    splash.close();
    image.dispose();
    for (int i = 0; i < count[0]; i++) {
    shells[i].open();
    }
    }
    });
    while (count[0] != 0) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    display.dispose();
    }