Mouse Track Example
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MouseTrackExample {
final Display d;
final Shell s;
public MouseTrackExample() {
d = new Display();
s = new Shell(d);
s.setSize(250, 200);
s.setText("A MouseTrackListener Example");
final Button b = new Button(s, SWT.PUSH);
b.setText("Push Me");
b.setBounds(20, 50, 55, 25);
s.open();
final Color oldColor = b.getBackground();
b.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
b.setBackground(new Color(d, 0, 153, 153));
}
public void mouseExit(MouseEvent e) {
b.setBackground(oldColor);
}
});
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
public static void main() {
new MouseTrackExample();
}
}
Related examples in the same category