Şu satırı dahil ederiz
import org.apache.commons.lang3.event.EventListenerSupport;
Sınıfın içi şöyle
public class EventListenerSupport<L> implements Serializable {
// [...]
/**
* The list used to hold the registered listeners. This list is
* intentionally a thread-safe copy-on-write-array so that traversals over
* the list of listeners will be atomic.
*/
private List<L> listeners = new CopyOnWriteArrayList<>();
// [...]
}
create metodu
Örnek
Şöyle yaparız
import java.awt.event.ActionListener;import org.apache.commons.lang3.event.EventListenerSupport;EventListenerSupport<ActionListener> actionListeners = EventListenerSupport.create
(ActionListener.class);public void someMethodThatFiresAction() {ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "somethingCool");actionListeners.fire().actionPerformed(e);}
Hiç yorum yok:
Yorum Gönder