Friday, July 15, 2011

java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NIC extends JFrame implements ActionListener
{
JLabel NICno, Datofbath,Sex;
JTextField NIC,date,sex;
JButton ok,reset;
NIC()
{
super("Find the date of bath use NIC number");
Container c=getContentPane();
c.setLayout(new FlowLayout());
NICno=new JLabel("NIC number");
NIC=new JTextField(9);

Datofbath=new JLabel("Date of bath");
date=new JTextField(9);

Sex=new JLabel("SEX");
sex=new JTextField(9);

ok=new JButton("OK");
reset=new JButton("Reset");
ok.addActionListener(this);
reset.addActionListener(this);

c.add(NICno);
c.add(NIC);

c.add(Datofbath);
c.add(date);

c.add(Sex);
c.add(sex);
c.add(ok);
c.add(reset);
setSize(500,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
JButton but=(JButton)e.getSource();
if(but.getText()=="OK")
{
String ic=NIC.getText();
String t,d,l,s;
t=ic.substring(0,2);
d=ic.substring(2,5);
l=ic.substring(6,9);
int x,y,z,m;
m=0;
z=0;
x=Integer.parseInt(d);
y=Integer.parseInt(l);
System.out.print(d+"\n");
int[] a={31,60,91,121,152,182,213,244,274,305,335,366};
for(int i=0;i<a.length-1;i++)
{
if((x>=a[i])&&(x<a[i+1]))
{
z=x-a[i];
m=i+2;
}
else if(x<=a[1])
{
z=x;
m=1;
}
}
if(y>=500)
{
s="male";
}
else
{
s="female";
}
date.setText(t+"."+Integer.toString(m)+"."+Integer.toString(z));
sex.setText(s);
}
else if(but.getText()==("Reset"))
{
NIC.setText("");
date.setText("");
sex.setText("");
}
}
public static void main(String[] a)
{
NIC b=new NIC();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

No comments:

Post a Comment