Text Listener Event in Advanced Java Programming

Home  »  Java  »  Advance Java »  Java Event Handling »  TextListenerTest

Text events are sent to text components(text field and text areas) when a change occurs to the text they contain. This happens when the user types something or when a program executes a method such as a setText().

The following is the definition of the TextEvent class:


A text component can process its own text events by calling enableEvents(AWTEvent.TEXT_EVENT_MASK) and providing a processTextEvent() method. Alternatively, a text component can delegate text events to a listener that implements the TextListener interface:



The following applet contains two text areas: the upper one delegates text events to the applet, and the lovwer one handles its own text events. Both event handlers just print a message to the console.



The above code will be stored in the file called TextListenerTest.java, which on compilation will crate a class file called TextListenerTest.class. Now compile this file using below commands in the DOS mode:

C:\>jdk1.4\bin>javac TextListenerTest.java
C:\>jdk1.4\bin>appletviewer TextListenerTest.java




"Output of TextListenerTest.class"
Output of TextListenerTest.class in DOS mode


Download Complete Program

  -  



Event Listener


Action Listener Adjustment Listener Mouse Listener
Mouse Motion Listener Window Listener Key Listener
Focus Listener ITEM Listener Text Listener



No comments:

Post a Comment