Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: What's Worng  (Read 916 times)
0 Members and 1 Guest are viewing this topic.
captainpirate
Junior Member
*

Reputation: 0
Offline Offline
Posts: 4
Referrals: 0

Awards
« on: February 21, 2010, 08:58:27 PM »

Quote
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.

Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #1 on: February 22, 2010, 07:45:33 AM »

yes, this is the right place.  Please use the codetag to hightlight your code though. --> geshi --> java wink tongue

Define "right output" what are you expecting?

Take a look at your code at line 4, that might be the line what you are looking for, if not let us know what u exactly want.
ageTxt.setText("0")

Code
GeSHi (java):
  1.    agelbl=new JLabel("Age");
  2.        ageTxt=new JTextField();
  3.        add(agelbl);
  4.        add(ageTxt);
  5.        ageTxt.setText("0");
Created by GeSHI 1.0.7.20

Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here