import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MouseTrackAdapter {
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());
MouseTrackAdapter listener = new MouseEnterExitListener();
label.setText("Point your cursor here ...");
label.setBounds(30, 30, 200, 30);
label.addMouseTrackListener(listener);
shell.setSize(260, 120);
shell.open();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
class MouseEnterExitListener extends MouseTrackAdapter {
public void mouseEnter(MouseEvent e) {
System.out.println("Cursor enters the label");
}
public void mouseExit(MouseEvent arg0) {
System.out.println("Cursor leaves the label");
}
}
|