source: trunk/src/gcc/libjava/java/awt/TextField.java@ 681

Last change on this file since 681 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.7 KB
Line 
1/* TextField.java -- A one line text entry field
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt;
40
41import java.awt.event.ActionEvent;
42import java.awt.event.ActionListener;
43import java.awt.peer.TextFieldPeer;
44import java.awt.peer.TextComponentPeer;
45import java.awt.peer.ComponentPeer;
46
47/**
48 * This class implements a single line text entry field widget
49 *
50 * @author Aaron M. Renn ([email protected])
51 */
52public class TextField extends TextComponent implements java.io.Serializable
53{
54
55/*
56 * Static Variables
57 */
58
59// Serialization constant
60private static final long serialVersionUID = -2966288784432217853L;
61
62/*************************************************************************/
63
64/*
65 * Instance Variables
66 */
67
68/**
69 * @serial The number of columns in the text entry field.
70 */
71private int columns;
72
73/**
74 * @serial The character that is echoed when doing protected input
75 */
76private char echoChar;
77
78// List of registered ActionListener's for this object.
79private ActionListener action_listeners;
80
81/*************************************************************************/
82
83/*
84 * Constructors
85 */
86
87/*
88 * Initializes a new instance of <code>TextField</code> that is empty
89 * and has one column.
90 */
91public
92TextField()
93{
94 this("", 1);
95}
96
97/*************************************************************************/
98
99/**
100 * Initializes a new instance of <code>TextField</code> containing
101 * the specified text. The number of columns will be equal to the
102 * length of the text string.
103 *
104 * @param text The text to display in the field.
105 */
106public
107TextField(String text)
108{
109 this(text, text.length());
110}
111
112/*************************************************************************/
113
114/**
115 * Initializes a new instance of <code>TextField</code> that is empty
116 * and has the specified number of columns.
117 *
118 * @param columns The number of columns in the text field.
119 */
120public
121TextField(int columns)
122{
123 this("", columns);
124}
125
126/*************************************************************************/
127
128/**
129 * Initializes a new instance of <code>TextField</code> with the
130 * specified text and number of columns.
131 *
132 * @param text The text to display in the field.
133 * @param columns The number of columns in the field.
134 */
135public
136TextField(String text, int columns)
137{
138 super(text);
139 this.columns = columns;
140}
141
142/*************************************************************************/
143
144/*
145 * Instance Methods
146 */
147
148/**
149 * Returns the number of columns in the field.
150 *
151 * @return The number of columns in the field.
152 */
153public int
154getColumns()
155{
156 return(columns);
157}
158
159/*************************************************************************/
160
161/**
162 * Sets the number of columns in this field to the specified value.
163 *
164 * @param columns The new number of columns in the field.
165 *
166 * @exception IllegalArgumentException If columns is less than zero.
167 */
168public synchronized void
169setColumns(int columns)
170{
171 if (columns < 0)
172 throw new IllegalArgumentException("Value is less than zero: " +
173 columns);