Getting started with Java Applet
YY435
Pacific Network Academy
Third day
5. Text editing area (TextField and Textarea)
There are two basic components for processing text in Java: single line text box textfield and multi-line text area Textarea, they are subclasses of TextComponent. The initial text string in the text component can also be indicated when you create a text component.
example:
What is the above example uses Java? Its syntax is as follows:
... // The same as the previous example 1. TextField text1 = new textfiled ("TextField", 20); 2. Text1.addActionListener (this); 3. Textarea text2 = New Textarea ("Textarea", 4, 20); 4. TEXT2.AddTextListener (this); 5. add (text1); 6. Add (text2); ... 8. Public void textValueChanged (TextEvent E) 9. {10.} ... // The same as the previous example
analysis:
Chapter 1: Call the function textFile to establish the first tag text1, the initial string is
"Textfield", the length of 20 characters;
Line 2: Add the monitor function to Text1 to respond to its event changes.
Chapter 3: Call the function textarea to establish the second tag text2, the initial string is
"Teatarea", a total of 4 lines, and each row is also the length of 20 strings.
Chapter 4: Add a monitor function for Text2 to respond to its event changes.
Chapter 5: Add the label 1 to the container to make it displayed on the screen.
Chapter 6: Similarly, the label 2 is added to the container to make it displayed on the screen.
In addition to inheriting the method of the TextComponent class, TextField also has some special
Method, for example, for password input, required input content to display "*", can be called
The following method:
TextField TF = New TextField ("Enter the password:");
Tf.sechochar ('*');
that's it.
Textarea also has its own special way:
Append (String S) adds a string after the text existing in the current text area
"s" content. Insert (string s, int index) method inserts the contents of the string s into
There is a designated sequence number of the text.