Advertisement
Methods | Description |
---|---|
public String paramString() | Returns the String describing the TextEvent. |
Methods | Description |
---|---|
public void textValueChanged(TextEvent e) | This method is called when a value in textfield or textarea is entered or edited. |
Methods | Description |
---|---|
public void addTextListener( TextListener object ) | Where, object is an object of the class that has implemented the TextListener interface. Doing this, registers the class to listen and respond to an event of type TextEvent, when a textfield or textarea is entered or edited. |
Advertisement
import java.awt.*;
import java.awt.event.*;
public class TextEventEx1 implements TextListener
{
Label label1, label2;
TextField field1;
Frame jf;
String str;
TextEventEx1()
{
jf = new Frame("Handling TextEvent");
label1= new Label("Type in the textfield, to see the textevents it generates -", Label.CENTER);
label2= new Label();
field1 = new TextField(25);
jf.setLayout(new FlowLayout());
jf.add(label1);
jf.add(field1);
jf.add(label2);
//Registering the class TextEventEx1 to catch and respond to mouse text events
field1.addTextListener(this);
jf.setSize(340,200);
jf.setVisible(true);
}
public void textValueChanged(TextEvent te)
{
label2.setText(te.paramString());
jf.setVisible(true);
}
public static void main(String... ar)
{
new TextEventEx1();
}
}
When you run the code, you are presented a window that shows an empty textfield.
import java.awt.*;
import java.awt.event.*;
public class TextEventEx2 implements TextListener
{
Label label1, label2;
TextArea area1;
Frame jf;
String str;
TextEventEx2()
{
jf = new Frame("Handling TextEvent");
label1= new Label("Type in the TextArea, to see the TextEvent -", Label.CENTER);
label2= new Label();
area1 = new TextArea(5,20); //calling TextField(String)
jf.setLayout(new FlowLayout());
jf.add(label1);
jf.add(area1);
jf.add(label2);
//Registering the class TextEventEx2 to catch and respond to mouse text events
area1.addTextListener(this);
jf.setSize(300,200);
jf.setVisible(true);
}
public void textValueChanged(TextEvent te)
{
label2.setText(te.paramString());
jf.setVisible(true);
}
public static void main(String... ar)
{
new TextEventEx2();
}
}
When you run the code, you are presented a window that shows an empty textarea.
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement