|
JHotDraw 7.0.9 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jhotdraw.draw.action.GenericListener
public abstract class GenericListener
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);
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 |
---|
public static java.lang.Object create(java.lang.Class listenerInterface, java.lang.String listenerMethodName, java.lang.Object target, java.lang.String targetMethodName)
create(listenerMethod, targetObject, targetMethod)
.
This version looks up the listener and target Methods, so you don't have to.
public static java.lang.Object create(java.lang.reflect.Method listenerMethod, java.lang.Object target, java.lang.reflect.Method targetMethod)
listenerMethod
. In this new class,
listenerMethod
will apply target.targetMethod
to the incoming Event.
|
Copyright 1996-2007 (c) JHotDraw.org. Some rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |