summaryrefslogtreecommitdiff
path: root/java/apps/NexusII/classes/awtCommand/CTextField.java
blob: 146f13206e5160ea7602faf54f601234e2a1e96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright 1996 Jan Newmarch, University of Canberra.
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies.  The author
 * makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without
 * express or implied warranty.
 */

package awtCommand;

import java.awt.*;

public class CTextField extends TextField {

    protected Command actionCommand = null,
		      gotFocusCommand = null,
		      lostFocusCommand = null;

    /**
     * Constructs a new CTextField.
     */
    public CTextField() {
	super();
    }

    /**
     * Constructs a new CTextField initialized with the specified columns.
     * @param cols the number of columns
     */
    public CTextField(int cols) {
	super(cols);
    }

    /**
     * Constructs a new CTextField initialized with the specified text.
     * @param text the text to be displayed
     */
    public CTextField(String text) {
	super(text);
    }


    /**
     * Constructs a new CTextField initialized with the specified text and columns.
     * @param text the text to be displayed
     * @param cols the number of columns
     */
    public CTextField(String text, int cols) {
	super(text, cols);
    }


    /**
     * Called when Enter is pressed in the text field.
     * This results in a call to the actionCommand object 
     * with <code>what</code> set to the text contents.
     */
    public boolean action(Event evt, Object what) {
	if (actionCommand != null)
            actionCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when the text field gains the focus.
     * This results in a call to the gotFocusCommand object 
     * with <code>what</code> set to null.
     */
    public boolean gotFocus(Event evt, Object what) {
	if (gotFocusCommand != null)
            gotFocusCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when the text field loses the focus.
     * This results in a call to the lostFocusCommand object 
     * with <code>what</code> set to null.
     */
    public boolean lostFocus(Event evt, Object what) {
	if (lostFocusCommand != null)
            lostFocusCommand.execute(this, evt, what);
	return false;
    }

   /**
    * Sets the actionCommand object.
    */
    public void setActionCommand(Command c) {
	actionCommand = c;
    }

 
   /**
    * Sets the gotFocusCommand object.
    */
    public void setGotFocusCommand(Command c) {
	gotFocusCommand = c;
    }

    /**
     * Sets the lostFocusCommand object.
     */
    public void setLostFocusCommand(Command c) {
	lostFocusCommand = c;
    }
}