JHotDraw 7.4.1

org.jhotdraw.gui.event
Class GenericListener

java.lang.Object
  extended by org.jhotdraw.gui.event.GenericListener

public abstract class GenericListener
extends java.lang.Object

The GenericListener creates anonymous listener classes at runtime.

Usage:

 public class Demo {
   JPanel root = new JPanel(new BorderLayout());
   JLabel label = new JLabel(" ");

   public void myButtonAction(ActionEvent e) {
     label.setText("buttonAction");
   }

   public void myMouseEntered(MouseEvent e) {
     label.setText("mouseEntered: "+e.toString());
   }

   Demo() {
     JButton button = new JButton("Button with Dynamic Listener");

     //This listener will be generated at run-time, for example at run-time
     // an ActionListener class will be code-generated and then
     // class-loaded.  Only one of these is actually created, even
     // if many calls to GenericListener.create(ActionListener.class ...)
     // are made.
     ActionListener actionListener = (ActionListener)(GenericListener.create(
       ActionListener.class,
       "actionPerformed",
       this,
       "myButtonAction")
     );
     button.addActionListener(actionListener);

     // Here's another dynamically generated listener.  This one is
     // a little different because the listenerMethod argument actually
     // specifies one of many listener methods.  In the previous example
     // "actionPerformed" named the one and only ActionListener method.
     MouseListener mouseListener = (MouseListener)(GenericListener.create(
       MouseListener.class,
       "mouseEntered",
       this,
       "myMouseEntered")
     );
     button.addMouseListener(mouseListener);
 

Version:
$Id: GenericListener.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer

Method Summary
static java.lang.Object create(java.lang.Class listenerInterface, java.lang.String listenerMethodName, java.lang.Object target, java.lang.String targetMethodName)
          A convenient version of create(listenerMethod, targetObject, targetMethod).
static java.lang.Object create(java.lang.reflect.Method listenerMethod, java.lang.Object target, java.lang.reflect.Method targetMethod)
          Return an instance of a class that implements the interface that contains the declaration for listenerMethod.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static java.lang.Object create(java.lang.Class listenerInterface,
                                      java.lang.String listenerMethodName,
                                      java.lang.Object target,
                                      java.lang.String targetMethodName)
A convenient version of create(listenerMethod, targetObject, targetMethod). This version looks up the listener and target Methods, so you don't have to.


create

public static java.lang.Object create(java.lang.reflect.Method listenerMethod,
                                      java.lang.Object target,
                                      java.lang.reflect.Method targetMethod)
Return an instance of a class that implements the interface that contains the declaration for listenerMethod. In this new class, listenerMethod will apply target.targetMethod to the incoming Event.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.