Example usage for java.beans EventSetDescriptor getAddListenerMethod

List of usage examples for java.beans EventSetDescriptor getAddListenerMethod

Introduction

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

Prototype

public synchronized Method getAddListenerMethod() 

Source Link

Document

Gets the method used to add event listeners.

Usage

From source file:EventTracerTest.java

/**
 * Add a listener to the given event set
 * @param c a component//from w ww.ja v a2s.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
}