# Synthax to add the Action/ActionPerformed capability

**URL:** <https://forum.inductiveautomation.com/t/synthax-to-add-the-action-actionperformed-capability/5783>\
**Category:** Module Development\
**Created:** [February 1, 2013, 10:58am UTC](https://forum.inductiveautomation.com/t/synthax-to-add-the-action-actionperformed-capability/5783 "2013-02-01T10:58:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 1, 2013, 10:58am UTC](https://forum.inductiveautomation.com/t/synthax-to-add-the-action-actionperformed-capability/5783/1 "2013-02-01T10:58:44Z")

</div>

I use the AbstractVisionComponent  
I’m looking for the synthax to add the Action/ActionPerformed capability on my component ?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 1, 2013, 2:34pm UTC](https://forum.inductiveautomation.com/t/synthax-to-add-the-action-actionperformed-capability/5783/2 "2013-02-01T14:34:26Z")

</div>

All you have to do is override the initEventSets function on your component’s bean info class to include an actionPerformed event:`@Override
protected void initEventSets() throws IntrospectionException {
	super.initEventSets();
	addEventSet(YourComponentClass.class, "action", ActionListener.class, "actionPerformed");
}`Then make your component class either extends a swing component that has action listeners or make it yourself. It is easier if you extend a class that has them already.

If you make it yourself you have to add the following variable to your class:`protected EventListenerList listenerList = new EventListenerList();`Then you have to add three functions to your class:[code]public void addActionListener(ActionListener l) {  
listenerList.add(ActionListener.class, l);  
}

public void removeActionListener(ActionListener l) {  
listenerList.remove(ActionListener.class, l);  
}

public ActionListener[] getActionListeners() {  
return (ActionListener[])(listenerList.getListeners(  
ActionListener.class));  
}[/code]Lastly, you will need to let the listeners know the event happened somewhere:`protected void fireActionPerformed() {
        Object[] listeners = listenerList.getListenerList();
        ActionEvent e = null;
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ActionListener.class) {
                if (e == null) {
                      e = new ActionEvent(YourComponentClass.this,
                                          ActionEvent.ACTION_PERFORMED,
                                          "SomeAction");
                }
                ((ActionListener)listeners[i+1]).actionPerformed(e);
            }          
        }
    }`That is it!

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [June 5, 2013, 8:18pm UTC](https://forum.inductiveautomation.com/t/synthax-to-add-the-action-actionperformed-capability/5783/3 "2013-06-05T20:18:13Z")

</div>

![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

just another question,

how to filter the event “SomeAction” in python script called on “actionPerformed”  
I fire actionPerformed for 2 differents events : “action1”, “action2”
