API java : EventListenerList


javax.swing.event
Class EventListenerList

java.lang.Object
  extended by javax.swing.event.EventListenerList
All Implemented Interfaces:
Serializable

public class EventListenerList
extends Object
implements Serializable

A class that holds a list of EventListeners. A single instance can be used to hold all listeners (of all types) for the instance using the list. It is the responsiblity of the class using the EventListenerList to provide type-safe API (preferably conforming to the JavaBeans spec) and methods which dispatch event notification methods to appropriate Event Listeners on the list. The main benefits that this class provides are that it is relatively cheap in the case of no listeners, and it provides serialization for event-listener lists in a single place, as well as a degree of MT safety (when used correctly). Usage example: Say one is defining a class that sends out FooEvents, and one wants to allow users of the class to register FooListeners and receive notification when FooEvents occur. The following should be added to the class definition:

  1. EventListenerList listenerList = new EventListenerList();
  2. FooEvent fooEvent = null;
  3.  
  4. public void addFooListener(FooListener l) {
  5. listenerList.add(FooListener.class, l);
  6. }
  7.  
  8. public void removeFooListener(FooListener l) {
  9. listenerList.remove(FooListener.class, l);
  10. }
  11.  
  12.  
  13. // Notify all listeners that have registered interest for
  14. // notification on this event type. The event instance
  15. // is lazily created using the parameters passed into
  16. // the fire method.
  17.  
  18. protected void fireFooXXX() {
  19. // Guaranteed to return a non-null array
  20. Object[] listeners = listenerList.getListenerList();
  21. // Process the listeners last to first, notifying
  22. // those that are interested in this event
  23. for (int i = listeners.length-2; i>=0; i-=2) {
  24. if (listeners[i]==FooListener.class) {
  25. // Lazily create the event:
  26. if (fooEvent == null)
  27. fooEvent = new FooEvent(this);
  28. ((FooListener)listeners[i+1]).fooXXX(fooEvent);
  29. }
  30. }
  31. }
foo should be changed to the appropriate name, and fireFooXxx to the appropriate method name. One fire method should exist for each notification method in the FooListener interface.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.


Field Summary
protected  Object[] listenerList
           
 
Constructor Summary
EventListenerList()
           
 
Method Summary
<T extends EventListener>
void
add(Class<T> t, T l)
          Adds the listener as a listener of the specified type.
 int getListenerCount()
          Returns the total number of listeners for this listener list.
 int getListenerCount(Class<?> t)
          Returns the total number of listeners of the supplied type for this listener list.
 Object[] getListenerList()
          Passes back the event listener list as an array of ListenerType-listener pairs.
<T extends EventListener>
T[]
getListeners(Class<T> t)
          Return an array of all the listeners of the given type.
<T extends EventListener>
void
remove(Class<T> t, T l)
          Removes the listener as a listener of the specified type.
 String toString()
          Returns a string representation of the EventListenerList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listenerList

protected transient Object[] listenerList
Constructor Detail

EventListenerList

public EventListenerList()
Method Detail

getListenerList

public Object[] getListenerList()
Passes back the event listener list as an array of ListenerType-listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners. WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.


getListeners

public <T extends EventListener> T[] getListeners(Class<T> t)
Return an array of all the listeners of the given type.

Returns:
all of the listeners of the specified type.
Throws:
ClassCastException - if the supplied class is not assignable to EventListener
Since:
1.3

getListenerCount

public int getListenerCount()
Returns the total number of listeners for this listener list.


getListenerCount

public int getListenerCount(Class<?> t)
Returns the total number of listeners of the supplied type for this listener list.


add

public <T extends EventListener> void add(Class<T> t,
                                          T l)
Adds the listener as a listener of the specified type.

Parameters:
t - the type of the listener to be added
l - the listener to be added

remove

public <T extends EventListener> void remove(Class<T> t,
                                             T l)
Removes the listener as a listener of the specified type.

Parameters:
t - the type of the listener to be removed
l - the listener to be removed

toString

public String toString()
Returns a string representation of the EventListenerList.

Overrides:
toString in class Object
Returns:
a string representation of the object.

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-2397
Document créé le 31/08/06 03:59, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-javax/swing/event/EventListenerList.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,71 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Le rôle d'un ami, c'est de se trouver à votre côté quand vous êtes dans l'erreur puisque tout le monde sera à côté de vous quand vous aurez raison.

Mark Twain
 
l'infobrol
Nous sommes le Samedi 02 Juin 2012, 04:51, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)