七年的爱
手中没有剑,我如何保护她;手中握着剑,我如何抱紧她!
posts - 7,comments - 3,trackbacks - 0
     关于swt的欢迎界面的例子,网上找了很就没有。后来自己就想用一个没有边框的shell加上一个滚动条来实现,具体的怎么用滚动条来检视后台,我还是没找到例子,现在就用一个白痴滚动条来暂时代替一下。白痴滚动条也就是想windows启动界面时出现的那样,一直不停的滚呀滚,呵呵。代码如下,

package com.sinosafe.swtdemo.welcome;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
/**
 *
 * @author zhong39
 * 一个简单的启动界面的例子
 *
 */

public class WelcomeInterface {
 
 private static Shell shell;

 public static void main(String[] args) {
  Display display = new Display();
  shell = new Shell(display, SWT.NO_TRIM |SWT.ON_TOP);
  createContents(shell);
  shell.setBounds(400, 200, 310, 250);
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();
 }
 protected static void createContents(Shell shell) {
  shell.setLayout(new FillLayout());
  Composite cm = new Composite(shell ,SWT.None);
  cm.setLayout(new GridLayout(1,false));
  Image ico = new Image(Display.getDefault(), "icons/welcome.gif");
  Label label = new Label(cm,SWT.None);
  label.setImage(ico);
  final ProgressBar progressBar = new ProgressBar(cm, SWT.INDETERMINATE);
  progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  
 }
}


具体在我一个应用程序中怎么使用,
我暂时的想法是在程序启动界面开始时先传一个display过去,先启动这个界面,在启动应用程序界面,和要加载的数据,最后调用welcomeClose方法来关闭,下面是,修改过的代码.

package com.sinosafe.premium.application;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

/**
 *
 * @author zhong39
 *
 */

public class WelcomeInterface {
 
 private Shell welcomeShell;
 
 public void open(Display display) {
  //Display display = new Display();
  welcomeShell = new Shell(display, SWT.NO_TRIM);
  createContents(welcomeShell);
  welcomeShell.setBounds(400, 200, 310, 250);
  welcomeShell.open();
 }
 protected  void createContents(Shell shell) {
  shell.setLayout(new FillLayout());
  Composite cm = new Composite(shell ,SWT.None);
  cm.setLayout(new GridLayout(1,false));
  Image welcome = new Image(Display.getDefault(), "images/welcome.gif");
  Label label = new Label(cm,SWT.None);
  label.setImage(welcome);
  ProgressBar progressBar = new ProgressBar(cm, SWT.INDETERMINATE);
  progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  
 }
 public void welcomeClose(){
  welcomeShell.close();
 }
}

总的来说就是shell的风格没有边框就是,其他的没什么特别的,还有图片的话,这个大家一定得弄个上去,不然的话肯定是显示不出来了。

好了,第开天辟地的第一篇就写个浮浅的东西,主要是这方面的网上好难早,所以我写的关于这方面的我个人的愚见,希望能节省到有这方面需要的人的时间。

posted on 2007-09-10 13:08 逝去的圣男 阅读(998) 评论(1)  编辑  收藏

FeedBack:
# re: swt 欢迎界面的制作
2008-10-14 15:38 | 秀逗
谢谢  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: