01: /*************************************************************************
02: * *
03: * 1) This source code file, in unmodified form, and compiled classes *
04: * derived from it can be used and distributed without restriction, *
05: * including for commercial use. (Attribution is not required *
06: * but is appreciated.) *
07: * *
08: * 2) Modified versions of this file can be made and distributed *
09: * provided: the modified versions are put into a Java package *
10: * different from the original package, edu.hws; modified *
11: * versions are distributed under the same terms as the original; *
12: * and the modifications are documented in comments. (Modification *
13: * here does not include simply making subclasses that belong to *
14: * a package other than edu.hws, which can be done without any *
15: * restriction.) *
16: * *
17: * David J. Eck *
18: * Department of Mathematics and Computer Science *
19: * Hobart and William Smith Colleges *
20: * Geneva, New York 14456, USA *
21: * Email: eck@hws.edu WWW: http://math.hws.edu/eck/ *
22: * *
23: *************************************************************************/package edu.hws.jcm.awt;
24:
25: import java.awt.*;
26: import java.awt.event.*;
27:
28: /**
29: * A compute button is a button that can have an associated Controller.
30: * When the user clicks the button, the compute() method of the
31: * Controller is called. This class really just exists for convenience.
32: */
33: public class ComputeButton extends Button {
34:
35: private Controller onUserAction; // The Controller whose compute()
36:
37: // method is called when the user clicks
38: // the button.
39:
40: /**
41: * Create a Compute button labeled "Compute!".
42: */
43: public ComputeButton() {
44: this ("Compute!");
45: }
46:
47: /**
48: * Create a Compute button displaying the given text.
49: */
50: public ComputeButton(String label) {
51: super (label);
52: setBackground(Color.lightGray);
53: enableEvents(AWTEvent.ACTION_EVENT_MASK);
54: }
55:
56: /**
57: * Set the controller whose compute() method is called
58: * when the user clicks this button.
59: */
60: public void setOnUserAction(Controller c) {
61: onUserAction = c;
62: }
63:
64: /**
65: * Return the controlller whose compute() method is
66: * called when the user clicks this button.
67: */
68: public Controller getOnUserAction() {
69: return onUserAction;
70: }
71:
72: /**
73: * This is called by the system when the user clicks the
74: * button. Not meant to be called directly.
75: */
76: public void processActionEvent(ActionEvent evt) {
77: if (onUserAction != null)
78: onUserAction.compute();
79: super .processActionEvent(evt);
80: }
81:
82: } // end class ComputeButton
|