import java.awt.Event;
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
*
* @author Administrator
*/
public class ElectionValidator extends JApplet {
JLabel namelbl,agelbl,natlbl;
JTextField nameTxt,ageTxt,natTxt;
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
namelbl=new JLabel("Name");
nameTxt=new JTextField();
add(namelbl);
add(nameTxt);
nameTxt.setText(" ");
agelbl=new JLabel("Age");
ageTxt=new JTextField();
add(agelbl);
add(ageTxt);
ageTxt.setText("0");
natlbl=new JLabel("Nationality");
natTxt=new JTextField();
add(natlbl);
add(natTxt);
natTxt.setText(" ");
}
public void paint(Graphics g){
String name=nameTxt.getText();
String agestr=ageTxt.getText();
String nat=natTxt.getText();
int age=Integer.parseInt(agestr);
if(nat.equalsIgnoreCase("Nepali")){
if(age<18){
g.drawString("Sorry"+name+"You are not eligible for general election as you are less than 18 yrs",10,100);
}
else{
g.drawString("Congratulation"+name+"You are eligible for general election",10,100);
}
}
else
g.drawString("Sorry"+name+"You are not eligible for general election as you are not nepali citizen",10,100);
}
public boolean action(Event ev,Object obj){
repaint();
return true;
}
}
I am not getting any right out put .
I got directly You are not eligible for general election as you are less than 18 yrs.
what's the error?
Help me.
I hope it is in right place.