views:

35

answers:

2

i want to emulate java.awt.MouseEvent class, and i define MouseEvent extends InputEvent which extends java.util.EventObject.

but when i run this in host mode, i got this error, it shows my InputEvent extends ComponentEvent. why? and how can i fix this? thanks!

java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(EventObject.java:38)
    at java.awt.AWTEvent.<init>(AWTEvent.java:279)
    at java.awt.event.ComponentEvent.<init>(ComponentEvent.java:96)
    at java.awt.event.InputEvent.<init>(InputEvent.java:204)
    at java.awt.event.MouseEvent.<init>(MouseEvent.java:548)
    at java.awt.event.MouseEvent.<init>(MouseEvent.java:450)

this situation just happened in host mode, when i compile and deploy it, all work fine.

A: 

You're using the wrong event - it should be MouseEvent (from the com.google.gwt.event.dom.client package), the one extending DomEvent<H>. See HasAllMouseHandlers for Widgets implementing all the mouse handlers (or check the individual interfaces for specific use cases).

Igor Klimer
u misunderstand my problem, i have define my own java.awt.MouseEvent and placed it in super-source folder. but the hierarchy of my own implement is not the same with jre's. in jre MouseEvent extends InputEvent extends ComponentEvent extends AWTEvent extends EventObject. in my own implement, MouseEvent extends InputEvent extends EventObject. got that?
the problem i described just happened in host mode. when i compile it, works fine. i just don't know why gwt use MouseEvent from jre instead of super-source in host mode.
A: 

None of the AWT libraries are part of the GWT emulated JRE libraries. If you want to listen for MouseEvent, you have to add Mouse*Handler to a widget extending FocusWidget. For example, addMouseDownHandler on FocusWidget and it's subclasses. You'll get a MouseEvent when the mouse is pressed over that widget.

Arthur Kalmenson