[
Lists Home |
Date Index |
Thread Index
]
吴湖 wrote:
> I 'v read a lot of w3c specs about dom event.
> But still I don't know how to create or invoke dom events in java.
> java 1.5 does have the org.w3c.dom.events package which contains lots
> of dom event interfaces, but how to implement them seems to be a
> question that we programmers should answer. Am I right? or there 'r
> already any implementation of these interfaces in java?
> Any help would mean a lot to me!
You create an event by casting the Document to a DocumentEvent and
calling createEvent.
You dispatch an event to a node in the tree by casting it to an
EventTarget and calling dispatchEvent on it.
You receive events by registering yourself as an EventListener on an
EventTarget (addEventListener), whereupon you will receive events
dispatched to that target (and possibly its descendents).
You can determine whether the implementation supports events by getting
the DOMImplementation (Document.getImplementation) and calling
hasFeature("events", "2.0") (or "uievents", "mutationevents",
"htmlevents").
GNU Classpath, used in gcj, jamvm, sablevm, kaffe, cacao, and most
other free JVMs, supports DOM events. I can't speak for other
implementations.
--
Chris Burdess
|