}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package br.com.waslleysouza.ss;
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import javax.swing.AbstractButton;
public class ActionListenerInstaller {
public ActionListenerInstaller() {
super();
}
public static void processAnnotations(Object obj)
{
try{
Class c1= obj.getClass();
for(Field f : c1.getDeclaredFields())
{
f.setAccessible(true);
ActionListenerFor a = f.getAnnotation(ActionListenerFor.class);
Object fObj = f.get(obj);
if(a!=null&&fObj!=null&&fObj instanceof AbstractButton)
{
Class<? extends ActionListener> listenerClazz = a.listener();
ActionListener a1= listenerClazz.newInstance();
AbstractButton ab =(AbstractButton)fObj;
ab.addActionListener(a1);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package br.com.waslleysouza.ss;
import java.awt.event.ActionListener;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ActionListenerFor
{
/* public ActionListenerFor() {
super();
} */
Class<? extends ActionListener> listener();
}