Saturday 3 December 2016

SWT: Event Handling

In my previous posts, I explained about different kinds of SWT widgets, Widgets themselves are not sufficient enough to develop an application, unless you add event handling mechanism to them.

In this and subsequent posts, I am going to explain different event handling mechanisms.

How to get notified about an event?
By adding listeners to SWT widget, you will get notified about the events occurred on given widget.

button1.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
                 System.out.println("Clicked me ");
         }
});

In the above snippet, I added SelectionListener to the button1. Whenever the button1 is clicked the widgetSelected method is called and the message is printed to console.

I am going to explain about most common event listeners in subsequent posts.

a.   Selection Listener
b.   Key Listener
c.    Mouse Listener
d.   Mouse Move Listener
e.   Mouse Track Listener
f.    Text Listeners

g.   Focus listeners


Previous                                                 Next                                                 Home

No comments:

Post a Comment