In my applet, when the first three letters of the country are entered into the textfield t and when the button is pressed it should display the full country name in textfield r, but I am not getting any output in textfield r. Why is nothing being displayed?
import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Copycat extends Applet implements ActionListener {
String country[]={"Japan","China","Russia","India","Germany","Iraq"};
Button n;
Label l;
TextField t;
TextField r;
String x;
public void init()
{
n=new Button("Click Me");
l=new Label("Enter the name of the Country");
t=new TextField();
r=new TextField();
add(n);
add(l);
add(t);
add(r);
n.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==n)
{
x=t.getText();
for(int i=0;i<=5;i++)
{
if((country[i].substring(0,3).equals(x)))
{
r.setText(country[i]);
}
}
}
}
}