望江門外——謝窮的Blog

          分享別人的經典 不如自己締造經典

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            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對象

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

                 

          //addMouseListener加入鼠標事件的監聽器

                  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() ;

                  }

              }

          }



          導入的類中  前三個是匿名內部事件所用到的

          import org.eclipse.jface.dialogs.MessageDialog;

          import org.eclipse.swt.events.MouseAdapter;

          import org.eclipse.swt.events.MouseEvent;


          運行結果 :



          雙擊“HelloWorld!”會彈出一個對話框 ,如圖所示 :

          posted on 2011-05-02 16:54 望江門外 閱讀(296) 評論(0)  編輯  收藏 所屬分類: SWT
          主站蜘蛛池模板: 开原市| 西平县| 彭州市| 正蓝旗| 策勒县| 昆明市| 砀山县| 仁怀市| 油尖旺区| 缙云县| 招远市| 横山县| 容城县| 明星| 丹东市| 海门市| 浦东新区| 南乐县| 诸暨市| 四平市| 阜康市| 富平县| 乌兰县| 河池市| 太仓市| 临沧市| 宁陵县| 武邑县| 桂平市| 新化县| 大洼县| 民权县| 镇雄县| 英超| 余干县| 西林县| 五峰| 襄垣县| 彰化市| 葫芦岛市| 西丰县|