Programmer's Guide > Programming and Scripting Techniques > Events > Event Handlers > Java
  
Java
In Java, it is necessary to cast the Document object to call the addEventListener method of the EventTarget interface. Also, note the event listener parameter is specified using an anonymous inner class.
Document doc = Application.getActiveDocument();
((EventTarget)doc).addEventListener("click",
new EventListener() {
public void handleEvent(Event event) {
Node node = (Node)event.getTarget();
String context = "";
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
context = "(" + node.getNodeName() + context;
}
node = node.getParentNode();
}
Application.print(context + "\n");
event.stopPropagation();
}
}, true);