七年的愛
          手中沒有劍,我如何保護她;手中握著劍,我如何抱緊她!
          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 逝去的圣男 閱讀(1014) 評論(1)  編輯  收藏

          FeedBack:
          # re: swt 歡迎界面的制作
          2008-10-14 15:38 | 秀逗
          謝謝  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 红桥区| 绥宁县| 玉溪市| 连平县| 乐亭县| 弥勒县| 类乌齐县| 玉山县| 宁津县| 安龙县| 樟树市| 龙口市| 苏尼特右旗| 南岸区| 开化县| 安国市| 盐源县| 集贤县| 高清| 平江县| 霍州市| 临湘市| 永宁县| 景德镇市| 六盘水市| 宝山区| 吴川市| 大石桥市| 冷水江市| 乌拉特前旗| 武陟县| 绵阳市| 简阳市| 新化县| 南部县| 汉源县| 崇仁县| 陈巴尔虎旗| 五台县| 龙陵县| 合肥市|