• Post Reply Bookmark Topic Watch Topic
  • New Topic

Text field validation

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have four Text fields, all the fields are having common event like keyPressed or insertUpdate. This event will be fired when action takes place in any of these text fields. What my question is, how to identify the control name which makes this event to be fired. Plese give the answer with any example.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by VenkataRRaju:
I have four Text fields, all the fields are having common event like keyPressed or insertUpdate. This event will be fired when action takes place in any of these text fields. What my question is, how to identify the control name which makes this event to be fired. Plese give the answer with any example.

Hi, VenkataRRaju,
To identify the event capture the event performed like `theEvent.getSource()' methods. pl. feel free to ask more details.
Here is the working code. Press enter key, to see the effect.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends Applet implements ActionListener
{
TextField txtFld1 = new TextField(10);
TextField txtFld2 = new TextField(10);
public void init()
{
add(txtFld1);
add(txtFld2);
txtFld1.addActionListener(this);
txtFld2.addActionListener(this);
}
public void actionPerformed(ActionEvent theEvent)
{
if (theEvent.getSource() == txtFld1)
{
System.out.println("txtFld1");
}
else
{
System.out.println("txtFld2");
}
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!