重現方式
直接上 SSCCE:
public class SpriteTestEP extends DrawComponent implements EntryPoint {
private RectangleSprite red = new RectangleSprite(200, 201, 100, 50);
private RectangleSprite none = new RectangleSprite(200, 201, 300, 50);
public SpriteTestEP() {
red.setFill(RGB.RED);
none.setFill(Color.NONE);
addSprite(red);
addSprite(none);
addSpriteOverHandler(new SpriteOverHandler() {
@Override
public void onSpriteOver(SpriteOverEvent event) {
log("Over : " + who(event.getSprite()));
}
});
addSpriteOutHandler(new SpriteOutHandler() {
@Override
public void onSpriteLeave(SpriteOutEvent event) {
log("Out : " + who(event.getSprite()));
}
});
}
private String who(Sprite sprite) {
return (sprite == red ? "red" : "none");
}
public static native void log(Object object) /*-{
console.log(
@java.lang.String::valueOf(Ljava/lang/Object;)(object)
);
}-*/;
@Override
public void onModuleLoad() {
//無關緊要,純粹 follow GXT 習慣 XD
Viewport vp = new Viewport();
vp.add(this);
RootPanel.get().add(vp);
}
}
操作步驟:
- 游標進入紅色區塊
- 慢慢水平移動滑鼠,直到離開紅色區塊