简体   繁体   English

Java-使用Netbeans将自定义事件侦听器添加到beanInfo中的eventSet中

[英]Java - Add custom event Listener to a eventSet in beanInfo with Netbeans

i have a custom bean and a custom eventListener, i need to show my event Listener in the events tab of my bean. 我有一个自定义bean和自定义eventListener,我需要在bean的events选项卡中显示我的事件Listener。

I think the solution is to add my event Listener to a beaninfo(i create it with netbeans, so it is auto-generated). 我认为解决方案是将事件监听器添加到beaninfo(我使用netbeans创建了它,因此它是自动生成的)。 There is a "wizard-way" to do this, or i have to hand-write my beaninfo? 有一个“向导方式”可以做到这一点,还是我必须手写我的beaninfo?

Thanks. 谢谢。

The solution is to have all methods for listener management, so Netbeans can recognize it and put it inside beaninfo. 解决方案是拥有用于侦听器管理的所有方法,以便Netbeans可以识别它并将其放入beaninfo中。

For example, if you have a custom listener called ActionDataListener, you have to add this methods: 例如,如果您有一个名为ActionDataListener的自定义侦听器,则必须添加以下方法:

    public void addActionDataListener(ActionDataListener listener) {
        actionDataListeners.add(listener);
    }

    public void removeActionDataListener(ActionDataListener listener) {
        actionDataListeners.remove(listener);
    }

    public ActionDataListener[] getActionDataListeners() {
        return actionDataListeners.toArray(new ActionDataListener[0]);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM