1. There are three methods for mouse mouselistener:
Mousedown: triggered by a click;
Mouseup: release;
Mousedoubleclick: Double-click;
Right-click on the left
2. attributes:
Button: INT: Left = 1; center = 2; Right = 3;
Statemask: Same as keylistener;
X, Y: coordinates at the bottom
Package COM. iteye. niewj. SWT. chapter1; import Org. eclipse. SWT. SWT; import Org. eclipse. SWT. events. mouseevent; import Org. eclipse. SWT. events. mouselistener; import Org. eclipse. SWT. layout. rowdata; import Org. eclipse. SWT. layout. rowlayout; import Org. eclipse. SWT. widgets. button; import Org. eclipse. SWT. widgets. display; import Org. eclipse. SWT. widgets. shell; import Org. eclipse. SWT. widgets. text; public class mouseevents How {/*** @ author niewj * @ since 2012-6-4 */public static void main (string [] ARGs) {// external shelldisplay display = display. getdefault (); final shell = new shell (Display); shell. setbounds (1, 20,100,450,500); shell. settext ("mouse event"); // layout manager rowlayout layout = new rowlayout (); layout. spacing = 30; layout. marginwidth = 30; layout. marginheight = 40; layout. wrap = true; layout. type = SWT. vertical; shell. setlayout (layout );/ /Rowdata controls the widget size and hide/* textrowdata textdata = new rowdata (); // true hides the widget. The occupied space is ignored, and textdata is moved from the bottom (back) to the Front (back. exclude = false; textdata. height = 150; textdata. width = 300; // * buttonrowdata btndata = new rowdata (); btndata. exclude = false; btndata. height = 30; btndata. width = 200; // 1. buttonfinal button = new button (shell, SWT. none); button. settext ("button above"); button. setlayoutdata (btndata); // 2. final text = new text (Shell, SWT. none); text. settext ("text box"); text. setlayoutdata (textdata); // 3. buttonfinal button button2 = new button (shell, SWT. none); button2.settext ("button below"); button2.setlayoutdata (btndata); text. addmouselistener (New mouselistener () {@ overridepublic void mouseup (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("Release text box; event Source :" + MSG) ;}@ overridepublic void mousedown (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("click the text box, source:" + MSG) ;}@ overridepublic void mousedoubleclick (mouseevent e) {string MSG = ""; Switch (E. button) {Case 1: MSG = ""; break; Case 2: MSG = ""; break; Case 3: MSG = ""; break;} text. settext ("double-click Text Box, event Source:" + MSG) ;}}); // display shell. O Pen (); While (! Shell. isdisposed () {If (! Display. readanddispatch () {display. Sleep () ;}} display. Dispose ();}}