JDK-4219696 : Get method for components which returns the eventListener.
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-03-12
  • Updated: 2000-05-17
  • Resolved: 2000-05-17
Related Reports
Duplicate :  
Duplicate :  
Description

Name: vi73552			Date: 03/11/99


I would like a way to get the event listeners of a component, so that they can be removed dynamically...
i.e.
my_Circle.addMouseMotionListener( new MouseMotionListener()
     {  public void mouseDragged( MouseEvent event)
        { ... };
       ...
     });
// then when necessary:

MouseMotionListener temp = my_Circle.getMouseMotionListener();
// the method ------------------------^
my_Circle.removeListener( temp );
...
// then later on....
my_Circle.addMouseMotionListener( temp );
(Review ID: 54445) 
======================================================================

Comments
EVALUATION Listeners can be added and removed from a Component using the present API. A reference to the Listener should be saved when it is created. Something like the following would do it: class DynamicListeners { Button aButton; ActionListener saveListener; public DynamicListener() { aButton = new Button(); saveListener = new ActionListener() { void actionPerformed(ActionEvent ev) { //Do stuff here } } } public void attachTheListener() { aButton.addActionListener(saveListener); } public void detachAndSaveTheListener() { aButton.removeActionListener(saveListener); } } brent.christian@eng 1999-03-11 Fix in Merlin. mike.bronson@eng 1999-12-23 This method was actually implemented in Kestrel. However, there is some work left to do: see 4290704 for details. eric.hawkes@eng 2000-05-16
23-12-1999