

package nic;
import javax.swing.JOptionPane;

public class NicInfo extends javax.swing.JFrame {
    
  String nicNumber;int day;int months;
    public NicInfo() {
        initComponents();
    }
    
 
   
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtBirthDay = new javax.swing.JTextField();
        txtGender = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtNicNumber = new javax.swing.JTextField();
        btnGo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("NIC");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Info"));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Your DoB :");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Gender :");
        jLabel3.setMaximumSize(new java.awt.Dimension(44, 14));
        jLabel3.setPreferredSize(new java.awt.Dimension(44, 14));
        jLabel3.setRequestFocusEnabled(false);

        txtBirthDay.setEditable(false);

        txtGender.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtGender)
                    .addComponent(txtBirthDay, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
                .addContainerGap(70, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtBirthDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Your NIC :");

        btnGo.setText("Go >>");
        btnGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnGo)
                            .addComponent(txtNicNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNicNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnGo)
                .addGap(21, 21, 21)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }

    private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {                                      
        {  
          String nicNumber=txtNicNumber.getText();
          int DaysOfMonths[]={31,29,31,30,31,30,31,31,30,31,30,31};
           if(nicNumber.length()==10){
            String year = nicNumber.substring(0, 2);
            int days= Integer.parseInt(nicNumber.substring(2, 5));
            
            if(days<500){
                txtGender.setText("Male");
                for(int i=0; i< DaysOfMonths.length;i++){
                    if(days<DaysOfMonths[i]){
                        months = i+1;
                        day = days;
                        break;
                        
                    }else{
                        days-= DaysOfMonths[i];
                    }
                }
                switch(months){
                    case 1:
                        txtBirthDay.setText(day+" / "+"January"+" / "+"19"+year);break;
                    case 2:
                        txtBirthDay.setText(day+" / "+"February"+" / "+"19"+year);break;
                    case 3:
                       txtBirthDay.setText(day+" / "+"March"+" / "+"19"+year);break;
                    case 4:
                        txtBirthDay.setText(day+" / "+"April"+" / "+"19"+year);break;
                    case 5:
                       txtBirthDay.setText(day+" / "+"May"+" / "+"19"+year);break;
                    case 6:
                        txtBirthDay.setText(day+" / "+"June"+" / "+"19"+year);break;
                    case 7:
                        txtBirthDay.setText(day+" / "+"July"+" / "+"19"+year);break;
                    case 8:
                        txtBirthDay.setText(day+"/"+"August"+"/"+"19"+year);break;
                    case 9:
                        txtBirthDay.setText(day+" / "+"September"+" / "+"19"+year);break;
                    case 10:
                       txtBirthDay.setText(day+" / "+"October"+" / "+"19"+year);break;
                    case 11:
                        txtBirthDay.setText(day+" / "+"November"+" / "+"19"+year);break;
                    case 12:
                        txtBirthDay.setText(day+" / "+"December"+" / "+"19"+year);break;
                    default:
                        break;
                }
                
            }else{
                txtGender.setText("Female");
                days-=500;
                for(int i=0; i< DaysOfMonths.length;i++){
                    if(days<DaysOfMonths[i]){
                        months = i+1;
                        day = days;
                        break;
                        
                    }else{
                        days-= DaysOfMonths[i];
                    }
                }
                switch(months){
                    case 1:
                        txtBirthDay.setText(day+" / "+"January"+" / "+"19"+year);break;
                    case 2:
                        txtBirthDay.setText(day+" / "+"February"+" / "+"19"+year);break;
                    case 3:
                        txtBirthDay.setText(day+" / "+"March"+" / "+"19"+year);break;
                    case 4:
                       txtBirthDay .setText(day+" / "+"April"+" / "+"19"+year);break;
                    case 5:
                        txtBirthDay.setText(day+" / "+"May"+" / "+"19"+year);break;
                    case 6:
                       txtBirthDay .setText(day+" / "+"June"+" / "+"19"+year);break;
                    case 7:
                     txtBirthDay .setText(day+" / "+"July"+" / "+"19"+year);break;
                    case 8:
                       txtBirthDay .setText(day+" / "+"August"+" / "+"19"+year);break;
                    case 9:
                       txtBirthDay .setText(day+" / "+"September"+" / "+"19"+year);break;
                    case 10:
                       txtBirthDay .setText(day+" / "+"October"+" / "+"19"+year);break;
                    case 11:
                       txtBirthDay .setText(day+" / "+"November"+" / "+"19"+year);break;
                    case 12:
                       txtBirthDay .setText(day+" / "+"December"+" / "+"19"+year);break;
                    default:
                        break;
                }
            }
            
        }else{
            JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(btnGo),"Invalid NIC number");
            txtNicNumber.setText("");
        }
        
        
    }
          


    }

    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NicInfo().setVisible(true);
            }
        });
    }
    
    
    private javax.swing.JButton btnGo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField txtBirthDay;
    private javax.swing.JTextField txtGender;
    private javax.swing.JTextField txtNicNumber;
    
    
}
