import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class EventListenerGeneral {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);
shell.setLayout(new GridLayout());
Listener listener = new MouseEnterExitListener();
label.setText("Point your cursor here ...");
label.setBounds(30, 30, 200, 30);
label.addListener(SWT.MouseEnter, listener);
label.addListener(SWT.MouseExit, listener);
shell.setSize(260, 120);
shell.open();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
class MouseEnterExitListener implements Listener {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.MouseEnter:
System.out.println("Cursor enters the label");
break;
case SWT.MouseExit:
System.out.println("Cursor leaves the label");
break;
}
}
}