<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    The Goal
    Keep walking……
    posts - 23,  comments - 1,  trackbacks - 0
    • The SWT event-processing cycle


    1. Once an SWT application begins running, its Display class sorts through this queue using its readAndDispatch() method and msg field, which acts as a handle to the underlying OS message queue.
    2. If it finds anything relevant, it sends the event to its top-level Shell object, which determines which widget should receive the event.
    3. The Shell then sends the event to the widget that the user acted on, which transfers this information to an associated interface called a listener.
    4. One of the listener’s methods performs the necessary processing or invokes another method to handle the user’s action, called an event handler.


    所在包:org.eclipse.swt.events ??

    • typed listeners and events

    typed listeners--只對某一類的用戶事件起作用,繼承TypedListener類
    typed events--與此類特定動作相關的事件,繼承TypedEvent類

    可通過add...Listener()method with the typed listener as the argument來將listener附加到widget。

    完整的typed events和listeners列表,如下:
    ?

    TypedEvent類包含了一些member field,他們提供與事件發生相關的一些信息,這些信息可以在event handler中使用來獲得與環境相關的信息。下圖為繼承自TypedEvent及EventObject類的fields:

    除此之外,很多的event類還有其他用來提供更多用戶動作信息的fields,如MouseEvent類的button field

    要將listener加入到code中,有兩個主要的方法:
    第一個是在component的add...Listener()中創建一個匿名接口,這樣可以使listener的作用域僅限于此component,示例代碼如下:
    Button button = new Button(shell, SWT.PUSH | SWT.CENTER);//創建了一個button,并將其加入到shell中
    button.addMouseListener(new MouseListener() //創建了一個匿名MouseListener接口,并將其與button關聯
    {
    public void mouseDown(MouseEvent e)
    {
    clkdwnEventHandler();
    }
    public void mouseUp(MouseEvent e)
    {
    clkupEventHandler();
    }
    public void mouseDoubleClick(MouseEvent e)
    {
    dblclkEventHandler(); //此接口中必須被實現的三個方法。一旦鼠標按下,放開或雙擊,就會有一個MouseEvent被發送到這三個方法中的一個,然后,此方法再調用相關聯的event-handling方法(即下文中的三個)。
    }
    });
    static void dblclkEventHandler()
    {
    System.out.println("Double click.");
    }
    static void clkdwnEventHandler()
    {
    System.out.println("Click - down.");
    }
    static void clkupEventHandler()
    {
    System.out.println("Click - up.");//event-handlers通過發送message到console來完成事件處理
    }

    上一類方法的缺點是此listener僅限于此component內,而第二種方法便可解決這種問題--獨立的聲明一個繼承MouseListener的接口,示例代碼如下:
    Button button = new Button(shell, SWT.PUSH | SWT.CENTER);
    button.addMouseListener(ExampleMouseListener);
    MouseListener ExampleMouseListener = new MouseListener()
    {
    public void mouseDoubleClick(MouseEvent e)
    {
    System.out.println("Double click.");
    }
    public void mouseDown(MouseEvent e)
    {
    System.out.println("Click - down.");
    }
    public void mouseUp(MouseEvent e)
    {
    System.out.println("Click - up.");
    }
    };

    使用MouseListener的缺點就是哪怕你只關心鼠標雙擊事件,卻仍要聲明其接口中所包含的所有方法。
    ?

    • Adapter

    Adapter是繼承了Listener接口并提供了所有required方法的實現的abstract類。也就是說如果你使用adapter而不是listener的話,你只需要寫你感興趣的方法

    只有那些listener有多個成員方法的event才有adapter,其完整列表見下圖:

    adapter同樣是通過add...Listener()方法來創建的,與listener類似,同樣也可通過匿名類和本地類兩種方法,下例為匿名類方法:
    button.addMouseListener(new MouseAdapter()
    {
    public void mouseDoubleClick(MouseEvent e)
    {
    dblclkEventHandler();
    }
    )};
    static void dblclkEventHandler()
    {
    System.out.println("Double click.");
    }

    • Keyboard events

    任何時候只要key被按下,就會創建KeyEvent,它有兩個子類:TraverseEvent 和VerifyEvent.
    TraverseEvent--當按下arrow key或tab key來focus on text widget時
    VerifyEvent--fires when the user enters text that the program needs to check before taking further action.

    除了繼承自TypedEvent和EventObject的field,KeyEvent還包括三個member field來提供那些與觸發事件的key相關的信息,具體如下:
    character--代表被按下key的char
    stateMask--Returns an integer representing the state of the keyboard modifier keys.By examining this integer, a program can determine whether any of the Alt, Ctrl, Shift, and Command keys are currently pressed.
    keyCode--Provides the SWT public constant corresponding to the typed key. KeyCode列表,見下圖:


    TraverseEvent中有兩個fields:
    1. doit--返回布爾值,若為真則允許在各個component間切換focus,若為假則不允許切換focus
    2. detail--It’s an integer that represents the identity of the key that caused the event. For example, if the user presses the Tab key to switch to a new component, the detail field will contain the SWT constant TRAVERSE_TAB_NEXT.

    每個類型的Control對于所給的traversal key都有不同的默認behavior,如果設doit為true,則override了其默認的設置。

    VerifyEvent的field:
    1.start和end--設定了輸入的范圍
    2.text--contains the input String under examination.
    3.doit--Having looked at the user’s text, you set the boolean doit field to allow (TRUE) or disallow (FALSE) the action.

    • untyped events

    更靈活,但不安全,不推薦使用。
    當一個代表著非類型化監聽器的監聽器類和GUI的某一組件相聯系時,它就能接受該組件所能發送的任一類事件。因此,你需要操控這由Event類代表的捕獲的全部事件,決定用戶執行的那個動作。然后,正確的事件處理方法就被調用。

    不是被包含在org.eclipse.swt.events包中,而是被包含在org.eclipse.swt.widgets包中。

    代碼示例如下:
    Listener listener = new Listener ()
    {
    public void handleEvent (Event event)
    {
    switch (event.type)
    {
    case SWT.KeyDown:
    if (event.character == 'b')
    System.out.println("Key"+event.character);
    break;
    case SWT.MouseDown:
    if (event.button == 3)
    System.out.println("Right click");
    break;
    case SWT.MouseDoubleClick:
    System.out.println("Double click");
    break;
    }
    }
    };
    Button button = new Button(shell, SWT.CENTER);
    button.addListener(SWT.KeyDown, listener);
    button.addListener(SWT.MouseDown, listener);
    button.addListener(SWT.MouseDoubleClick, listener);


    Event類包含了所有typed event中的所有field,此外還有一個type field,其所有的值列表如下:

    posted on 2006-03-23 16:32 JOO 閱讀(819) 評論(0)  編輯  收藏 所屬分類: SWT & JFace IN ACTION
    Hit the target!

    <2006年3月>
    2627281234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    常用鏈接

    留言簿(2)

    隨筆分類(23)

    隨筆檔案(22)

    文章檔案(1)

    相冊

    Neighbor

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 好看的亚洲黄色经典| 免费一级毛片一级毛片aa| 亚洲午夜久久影院| 玖玖在线免费视频| 久久久综合亚洲色一区二区三区 | 在线看片免费人成视频福利| 亚洲精品国产精品国自产观看 | 人人揉揉香蕉大免费不卡| 久久久久亚洲AV无码专区首| 久久青草国产免费观看| 亚洲国产精品第一区二区| 免费人成在线观看网站品爱网 | 99re6在线视频精品免费| 亚洲AV成人无码久久精品老人| 国产99视频精品免费专区| 亚洲综合国产精品| 一二三四免费观看在线电影 | 亚洲AV永久无码精品| 久久综合国产乱子伦精品免费| 亚洲国产成人在线视频| 最近中文字幕免费mv视频8| 国产精品自拍亚洲| 亚洲中文字幕无码不卡电影| 91久久青青草原线免费| 在线a亚洲老鸭窝天堂av高清| 亚洲?V无码成人精品区日韩| 动漫黄网站免费永久在线观看| 亚洲一区二区三区在线观看蜜桃| 日韩精品福利片午夜免费观着| 香蕉视频在线观看免费| 久久青青成人亚洲精品| 妞干网免费视频在线观看| 曰批免费视频播放免费| 婷婷亚洲综合五月天小说| 女性无套免费网站在线看| www一区二区www免费| 亚洲免费黄色网址| 中文字幕亚洲专区| 99国产精品永久免费视频| 色老头综合免费视频| 亚洲免费观看网站|