How to get all listenrs?
1 posts in topic
Flat View  Flat View

Posted By:   z_chen
Posted On:   Tuesday, September 3, 2002 01:46 AM

How do i get all the listeners that where added to an object & how do i remove them all?


Re: How to get all listenrs?

Posted By:   Axel_Richter  
Posted On:   Tuesday, September 3, 2002 05:27 AM

That does not become simple. If your objects are awt.components or subclasses, then you may use:

public EventListener[] getListeners(Class listenerType)

to get the listeners by listenerType. But you have to get each type individually. For ex:

MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class))
KeyListener[] kls = (KeyListener[])(c.getListeners(KeyListener.class))

Then you may test whether the appropriate types were present. For ex:

if (mls.length > 0) ...

For removing you have to use the individually remove-methods. For ex:

for (int i=0; i c.removeMouseListener(mls[i]);
for (int i=0; i c.removeKeyListener(kls[i]);
About | Sitemap | Contact