From:
Java language and program-oriented Programming (second edition)
Seventh chapter Fifth Section P223
1. [Code]java Code
/**
* This program mainly to practice text events, when entering text in a text box (TextField), will be in the Text field (TextField)
* Synchronized display of input text
*/
Import java.applet.*;
Import java.awt.*;
Import java.awt.event.*;
public class MyApplet extends Applet implements ActionListener, TextListener
{
TextField TF;
TextArea Ta;
public void Init ()
{
tf = new TextField (45);
Ta = new TextArea (5,45);
This.add (TF);
This.add (TA);
Tf.addactionlistener (this);
Tf.addtextlistener (this);
}
Single-line text (textevent) changes the event raised
public void textvaluechanged (TextEvent e)
{http://www.huiyi8.com/shijianzhou/
if (E.getsource () ==TF)
Ta.settext (((TextField) E.getsource ()). GetText ());
}
The time that is raised when a single line of text presses ENTER
public void actionperformed (ActionEvent e)
{Time axis effects
if (e.getsource () = = TF)
{
Ta.settext (""); Enter, text field empty
}
}
}
2.
Java Applet: Practicing text events for the TextField class and the TextArea class