望江門外——謝窮的Blog

          分享別人的經(jīng)典 不如自己締造經(jīng)典

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            6 Posts :: 1 Stories :: 1 Comments :: 0 Trackbacks
          一 、新建工程 ,名為myswt

          二 、建立窗體



          Next --  命名為HelloWorld ,包名為com.swtdesigner .



          三 、HelloWorld.java中的代碼如下  :

           

          package com.swtdesigner ;

          import org.eclipse.jface.dialogs.MessageDialog;

          import org.eclipse.swt.events.MouseAdapter;

          import org.eclipse.swt.events.MouseEvent;

          import org.eclipse.swt.widgets.Display;

          import org.eclipse.swt.widgets.Shell;

          import org.eclipse.swt.SWT;

          import org.eclipse.swt.widgets.Text;

          publicclass HelloWorld{

              publicstaticvoid main(String args []){

                 final Display display = Display.getDefault();

                 final Shell shell = new Shell() ;

                  shell.setSize(357,259) ;

                  shell.setText("SWT Application") ;

                 

                  //插入Text對(duì)象

                  Text text = new Text(shell,SWT.BORDER) ;

                 

          //addMouseListener加入鼠標(biāo)事件的監(jiān)聽器

                  text.addMouseListener(new MouseAdapter(){

                      publicvoid mouseDoubleClick(MouseEvent e){

                         MessageDialog.openInformation(null,"","Double Click !") ;

                      }

                  });

                  text.setText("Hello World !") ;

                  text.setBounds(50, 50, 100, 24) ;

                 

                  shell.layout() ;

                  shell.open();

                  while(!shell.isDisposed()){

                  if(!display.readAndDispatch())

                      display.sleep() ;

                  }

              }

          }



          導(dǎo)入的類中  前三個(gè)是匿名內(nèi)部事件所用到的

          import org.eclipse.jface.dialogs.MessageDialog;

          import org.eclipse.swt.events.MouseAdapter;

          import org.eclipse.swt.events.MouseEvent;


          運(yùn)行結(jié)果 :



          雙擊“HelloWorld!”會(huì)彈出一個(gè)對(duì)話框 ,如圖所示 :

          posted on 2011-05-02 16:54 望江門外 閱讀(296) 評(píng)論(0)  編輯  收藏 所屬分類: SWT

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 高平市| 泰兴市| 兴安县| 荥经县| 沙雅县| 济阳县| 辽宁省| 美姑县| 冀州市| 林甸县| 弋阳县| 高邮市| 姜堰市| 榆树市| 开鲁县| 丹凤县| 潮州市| 黄山市| 晋中市| 彝良县| 周宁县| 沙河市| 锦屏县| 宜黄县| 紫云| 高要市| 平遥县| 通许县| 承德县| 米易县| 平定县| 大姚县| 宁海县| 新龙县| 盐山县| 正镶白旗| 广安市| 铜川市| 河北省| 镇平县| 台山市|