Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Use SWT Listener Classes Effectively for Responsive Java UIs : Page 2

By using the SWT listener classes effectively as this article prescribes, you can win the hearts of your Java application users with highly responsive GUIs.


advertisement
Typed Listener API
SWT provides 16 different listener classes under the typed listener API.

Mouse-based Listeners
Mouse-based listeners capture the events generated by the mouse such as mouse-clicks and mouse moves.

MouseListener
MouseListener deals with the events generated when users press mouse buttons. When the user presses or releases a mouse button, it invokes the appropriate method:



void mouseDoubleClick(MouseEvent me) void mouseDown(MouseEvent me) void mouseUp(MouseEvent me)

MouseAdapter provides the basic definition of these methods.

MouseMoveListener
MouseMoveListener deals with the events generated as the user moves the mouse pointer. As the mouse moves, it invokes the mouseMove method:

void mouseMove(MouseEvent me)

MouseTrackListener
MouseTrackListener deals with the events generated as the user passes the mouse pointer (or hovers) over controls. This listener is used to display tool tip text messages:

void mouseEnter(MouseEvent me) void mouseExit(MouseEvent me) void mouseHover(MouseEvent me)

MouseTrackAdapter defines these methods, and developers can overwrite the definition of any method.

Text Listeners
Text listeners capture the events generated when a user modifies or is about to modify the text inside a text-widget..

VerifyListener
VerifyListener deals with the events generated when a user is about to modify text. It fires the event when the user is about to modify text in a text widget:

txt.addVerifyListener(new VerifyListener(){ public void verifyText(VerifyEvent ve){ ....... }});

Swing has no equivalent component that offers the same functionality.

ModifyListener
ModifyListener deals with the events generated when a user modifies text. It invokes the modifyText() method when the user modifies text. In the sample code, when you type text in the text widget you first see a Verify event message followed by a Modify event message.

Menu and MenuItem Listeners
Menu and MenuItem listeners deal with the events generated when a user activates or clicks the Menu or MenuItem widget.

ArmListener
ArmListener is a new listener functionality provided by SWT. It deals with the events generated when a user highlights a MenuItem with the mouse or keyboard but has not yet selected it. The widgetArmed(ArmEvent ae) is invoked when a widget is armed, or "about to be selected".

MenuListener
MenuListener deals with hiding and showing menus. When a menu is hidden or shown, the menuHidden() or menuShown() method is invoked, respectively.

HelpListener
SWT provides a direct association between the standard F1 key and the Help menu. HelpListener can be added to any control (or to any widget, as widgets are sub classes of control). In the sample code, the help listener is added to the shell to bring out help for the screen. This is a very helpful feature for complex UI screens.

Shell and Composite Listeners
Shell and composite listeners deal with the events generated when a user invokes or activates the Shell or Composite.

ShellListener
ShellListener is very helpful for managing resource allocation. Based on the state of a shell's changes, the appropriate method [shellActivated() or shellClosed() or shellDeactivated() or shellDeiconified() or shellIconified()] is invoked.

ControlListener
This type of listener does not exist in Swing. ControlListener deals with the events generated when a user moves and resizes controls. When the user moves and resizes a control, it invokes the controlMoved() or controlResized() method.

DisposeListener
When a widget is disposed, the widgetDisposed() method is invoked.

PaintListener
This type of listener does not exist in Swing. PaintListener deals with the events generated when the control needs painting. However, the paintControl method is invoked after a paint event occurs.

TraverseListener
When a traverse event occurs in a control, the keyTraversed method is invoked. Traversal keys are typically tab and arrow keys, along with certain other keys on some platforms. The feature enables users to traverse the control on an application by simply typing the traverse keys rather than positioning the mouse pointer on the control and clicking. Swing has no equivalent to this class.

The Rest Is Up to You
By using the SWT listener classes effectively as prescribed in this article, you can win the hearts of the application users with highly responsive UIs.



Raghu Donepudi, an independent contractor, currently is a technical manager for a federal government agency. He has a master's degree in Computer Science from Lamar University in Texas. He is a Sun-certified Java developer and the author of many software design techniques.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap