Java Applet: Practicing text events for the TextField class and the TextArea class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.