Another example of textfield using array and show data after search
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet
code="Search" height=200 width=200>
</applet>
*/
public class Search extends Applet
implements ActionListener
{
String
ename[
]={"ajay","kapil","sanjay","lalit","manoj"};
String
eid[
]={"e001","e101","e900","e890","e299"};
int
salary[ ]={10023,8900,8299,9000,7899};
TextField
txtid,txtname,txtsal;
Button
b1,b2;
public
void init()
{
Label
l1=new Label("Employee Id :");
add(l1);
txtid=new
TextField(20);
add(txtid);
Label
l2=new Label("Name
:");
add(l2);
txtname=new
TextField(20);
txtname.setEditable(false);
add(txtname);
Label
l3=new Label("Salary :");
add(l3);
txtsal=new
TextField(20);
txtsal.setEditable(false);
add(txtsal);
b1=new
Button("Search");
add(b1);
b1.addActionListener(this);
b2=new
Button("Reset");
add(b2);
b2.addActionListener(this);
}
public
void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
/*searching
for the employee id */
String
id=txtid.getText();
int
i=0;
for(i=0;i<5;i++)
{
if(id.equals(eid[i]))
{
/*set
the text boxes*/
txtname.setText(ename[i]);
txtsal.setText(salary[i]+"");
break;
}
}
}
else
{
/*clear
the text boxes */
txtid.setText("");
txtname.setText("");
txtsal.setText("");
}
}
}
Comments
Post a Comment