Results 1 to 2 of 2
  1. #1
    mcal is offline Member
    Join Date
    Jan 2008
    Posts
    39
    Rep Power
    0

    Default Class explanation

    Hey guys, i have a problem with this class. I can't understand exactly what is really doing. Can someone pls help me understand it? Thanks a lot.

    This is the code:


    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Calendar;
     
    import javax.swing.event.EventListenerList;
     
    public class ActionSupport {
     
    	protected EventListenerList listenerList = new EventListenerList();
    	private Object bean;
     
    	public ActionSupport(Object registeredBean) {
    		this.bean = registeredBean;
    	}
     
    	public void fireActionPerformed(String actionCommand) {
    		
    		Object[] listeners = listenerList.getListenerList();
    		ActionEvent e = null;
    		
    		for (int i = listeners.length - 2; i >= 0; i -= 2) {
    			if (listeners[i] == ActionListener.class) {
    				e = new ActionEvent(bean, ActionEvent.ACTION_PERFORMED, actionCommand, Calendar.getInstance().getTimeInMillis(), 0);
    				((ActionListener) listeners[i + 1]).actionPerformed(e);
    			}
    		}
    	}
     
    	public void addActionListener(ActionListener l) {
    		listenerList.add(ActionListener.class, l);
    	}
     
    	public void removeActionListener(ActionListener l) {
    		listenerList.remove(ActionListener.class, l);
    	}
    }

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    It is multiplexing the callback to more than one classes . Different listeners can be registered to this class and when the action is triggered this class calls all the listeners.
    dont worry newbie, we got you covered.

Similar Threads

  1. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  2. Inner class accessing outer class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 08:59 AM
  3. need a little explanation
    By cew27 in forum New To Java
    Replies: 7
    Last Post: 12-13-2007, 11:39 PM
  4. Explanation bout threading and concurrency?
    By cruxblack in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 10:33 AM
  5. I need didactic explanation
    By Eric in forum New To Java
    Replies: 2
    Last Post: 07-02-2007, 05:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •