diff --git a/projects/samskivert/src/java/com/samskivert/swing/Controller.java b/projects/samskivert/src/java/com/samskivert/swing/Controller.java index 73d9d0cd..f60badf1 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/Controller.java +++ b/projects/samskivert/src/java/com/samskivert/swing/Controller.java @@ -1,5 +1,5 @@ // -// $Id: Controller.java,v 1.13 2002/04/08 17:40:31 mdb Exp $ +// $Id: Controller.java,v 1.14 2002/04/26 02:31:32 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -27,6 +27,7 @@ import java.awt.event.ActionListener; import java.lang.reflect.Method; +import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.event.AncestorEvent; @@ -81,6 +82,13 @@ public abstract class Controller * button.addActionListener(Controller.DISPATCHER); * * + * or, use the provided convenience function: + * + *
+ * JButton button =
+ * Controller.createActionButton("Do thing", "dothing");
+ *
+ *
* The controllers in scope would then be requested (in order) to
* process the dothing action whenever the button was
* clicked.
@@ -296,6 +304,18 @@ public abstract class Controller
EventQueue.invokeLater(new ActionInvoker(event));
}
+ /**
+ * Creates a button and configures it with the specified label and
+ * action command and adds {@link #DISPATCHER} as an action listener.
+ */
+ public static JButton createActionButton (String label, String command)
+ {
+ JButton button = new JButton(label);
+ button.setActionCommand(command);
+ button.addActionListener(DISPATCHER);
+ return button;
+ }
+
/**
* This class is used to dispatch action events to controllers within
* the context of the AWT event dispatch mechanism.