// use of Trampolines: the GenericActionListener

// calls the this.doit() method when someone hits myDoItButton.
myDoItButton.addActionListener( new GenericActionListener( this, "doit" ) );

// calls that.close() method when someone hits myCloseButton
myCloseButton.addActionListener( new GenericActionListener( that, "close" ) );

// --------------------------------------------------------------

// You have to write a GenericActionListener class like this:
public class GenericActionListener implements ActionListener
   {
   String methodName;
   Object target;

   /**
    * constructor
    * @param target object whose method is to be called when
    *   the event happens.
    * @param methodName name of parameterless method on target
    *   to be called when the event happens.
    */
   public GenericActionListener ( Object target, String methodName )
      {
      this.target = target;
      this.methodName = methodName;
      }

   /**
    * @inheritDoc
    */
   public void actionPerformed ( ActionEvent e )

      {
      try
         {
         // call method using reflection
         Class[] argtypes = {};
         Method method = target.getClass().getMethod( methodNeme, argTypes );
         Object args = {};
         method.invoke( target, args );
         }
      catch ( Exception ex )
         {
         ex.printStackTrace();
         throw new IllegalArgumentException(
               "GenericActionListener: no such method "
               + methodName );
         }
      }
   }