Example usage for java.beans EventSetDescriptor getListenerType

List of usage examples for java.beans EventSetDescriptor getListenerType

Introduction

In this page you can find the example usage for java.beans EventSetDescriptor getListenerType.

Prototype

public Class<?> getListenerType() 

Source Link

Document

Gets the Class object for the target interface.

Usage

From source file:EventTracerTest.java

/**
 * Add a listener to the given event set
 * @param c a component//  w  ww.ja  v a  2  s .  c  o m
 * @param eventSet a descriptor of a listener interface
 */
public void addListener(Component c, EventSetDescriptor eventSet) {
    // make proxy object for this listener type and route all calls to the handler
    Object proxy = Proxy.newProxyInstance(null, new Class[] { eventSet.getListenerType() }, handler);

    // add the proxy as a listener to the component
    Method addListenerMethod = eventSet.getAddListenerMethod();
    try {
        addListenerMethod.invoke(c, proxy);
    } catch (InvocationTargetException e) {
    } catch (IllegalAccessException e) {
    }
    // ok not to add listener if exception is thrown
}