Turn Desktop View Off
by Dinesh Thakur

The java.awt.event.TextListener interface allows to react to changes the text contained in components of type TextField and TextArea. The addTextListener () method enables a text component to generate user events. the method TextValueChanged () receives events.


Its interface requires that the method be implemented textValueChanged whose associated event, java.awt.event.TextEvent, has a specific method interest listed below:

Method

Description

toString()

Returns the string associated with the event.

 

import java.awt.*;

import java.awt.event.*;
class JavaExampleTextEvent extends Frame implements TextListener
{
  TextField Txt;
  public JavaExampleTextEvent()
    {
      createAndShowGUI();
    }
      private void createAndShowGUI()
        {
          setTitle("Example of Text Listener");
          setLayout(new FlowLayout());
          Txt=new TextField(20);
          Txt.addTextListener(this);
          add(Txt);
          setSize(400,400);
          setVisible(true);
        }
          public void textValueChanged(TextEvent Evnt)
          {
             setTitle(Txt.getText());
          }
             public static void main(String aa[])
             {
                new JavaExampleTextEvent();
             }
 }

TextListener