码迷,mamicode.com
首页 > 其他好文 > 详细

e650. 激活事件

时间:2018-09-02 23:41:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:nts   objects   void   red   etl   cal   turn   table   selected   

An object wishing to fire item events must implement ItemSelectable. This example shows typical code that an object must implement to fire item events. When an item event is to be fired, fireItemEvent() should be called.

    public class MyComponent implements ItemSelectable {
        protected EventListenerList listenerList = new EventListenerList();
    
        public Object[] getSelectedObjects() {
            return selectedObjects;
        }
    
        public void addItemListener(ItemListener l) {
            listenerList.add(ItemListener.class, l);
        }
    
        public void removeItemListener(ItemListener l) {
            listenerList.remove(ItemListener.class, l);
        }
    
        // If the item is selected, sel should be true.
        void fireItemEvent(Object item, boolean sel) {
            ItemEvent evt = new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
                item, sel ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
    
            // Get list of listeners
            Object[] listeners = listenerList.getListenerList();
    
            // Send event to all listeners
            for (int i=0; i<listeners.length-2; i+=2) {
                if (listeners[i] == ItemListener.class) {
                    ((ItemListener)listeners[i+1]).itemStateChanged(evt);
                }
            }
        }
    }

 

Related Examples

e650. 激活事件

标签:nts   objects   void   red   etl   cal   turn   table   selected   

原文地址:https://www.cnblogs.com/borter/p/9575403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!