The
Text area is much like a text field, but it has more rows and some more compelling features. In addition, you can append, insert, or modify text at a given position on a text field. This seems to be a useful feature for text fields, so trying to find out what it is designed to do can create some confusion. We can think that if we need the function of "text area" everywhere, we can simply use a linear text area where we will use the text field in addition. In Java version 1.0, when they are not fixed, we also get a vertical and horizontal scroll bar for a text area. In Java version 1.1, modifications to the Advanced builder allow us to choose which scroll bar is current. The following example shows that the scroll bar is open only in the context of the Java1.0 version. In the next chapter we'll see a routine that proves the text area in Java version 1.1.
: Textarea1.java//Using The Text area control import java.awt.*;
Import java.applet.*;
public class TextArea1 extends Applet {button B1 = New button ("Text area 1");
Button B2 = New button ("Text area 2");
Button B3 = New button ("Replace Text");
button B4 = New button ("Insert Text");
TextArea T1 = new TextArea ("T1", 1, 30);
TextArea t2 = new TextArea ("T2", 4, 30);
public void Init () {Add (B1);
Add (t1);
Add (B2);
Add (T2);
Add (B3);
Add (B4); Public boolean action (Event evt, Object Arg) {if (Evt.target.equals (B1)) getAppletContext (). Showstatus (T1.G
Ettext ());
else if (evt.target.equals (B2)) {T2.settext ("Inserted by Button 2");
T2.appendtext (":" + T1.gettext ());
getAppletContext (). Showstatus (T2.gettext ());
else if (Evt.target.equals (b3)) {String s = "replacement";
T2.replacetext (S, 3, 3 + s.length ());
else if (evt.target.equals (B4)) T2.inserttext ("Inserted", 10); //Let's base class handle It:else return Super.action (EVT, ARG); return true; We ' ve handled it here}}///:~
There are several different text area builders in the program, one of which shows an initial string and line number and column number here. Different buttons display the get, append, modify, and insert text.