BirthDay
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.text.*;
import java.text.DateFormatSymbols;
import java.util.Calendar;
 public class BDay extends JFrame{
  int row,col;
  Container pane;
  JTextArea textArea;
  String output=" ",inputbd,Name;
  String fdt="MM/dd/yyyy";
  public static void main(String[] args){
    BDay brtdy=new BDay();
    brtdy.setBounds(100,100,350,250);
    brtdy.setVisible(true);
  }
 
 public BDay(){
   super("HAPPY BIRTHDAY");
   pane=getContentPane();
   pane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
   textArea=new JTextArea(row,col);
   addWindowListener(new WindowHandler());
 input();
        textArea.setText(output);
        pane.add(textArea);
   pane.add(new TopPanel(),BorderLayout.NORTH);
   pane.add(new BottomPanel(),BorderLayout.SOUTH);
  }
  void input(){
    String dformat,dform;
    int age;
      Name=JOptionPane.showInputDialog("Enter Name:");
      inputbd = JOptionPane.showInputDialog("Enter Date Of Birth in this form 
 try{
 SimpleDateFormat df= new SimpleDateFormat(fdt);
  df.setLenient(false);
 java.util.Date d = df.parse(inputbd);
 Calendar dateofbirth = Calendar.getInstance();
  dateofbirth.setTime(d);
 Calendar today = Calendar.getInstance();
 age = today.get(Calendar.YEAR) - dateofbirth.get(Calendar.YEAR);
  dformat = " MMMM, dd,EEEE--yyyy";
         dform="MM,dd,yyyy";
 SimpleDateFormat sdf = new SimpleDateFormat(dformat);
 SimpleDateFormat sdf2 = new SimpleDateFormat(dform);
        output +="Name:"+ Name + "\n\n"; 
        output +="Date of Birth:"+sdf2.format(dateofbirth.getTime())+"\n";
        output+="You were born:" + " " + sdf.format(dateofbirth.getTime())+ "\n\n";
 dateofbirth.set(Calendar.YEAR,2002);
      output +="You are"+" "+age+" "+"years old this year:"+" "+sdf.format(dateofbirth.getTime());
 }
   catch(ParseException e){
 JOptionPane.showMessageDialog(null,"Date is invalid ","Try another",JOptionPane.ERROR_MESSAGE);
 }
    }
  
  class WindowHandler extends WindowAdapter{
   public void windowClosing(WindowEvent e){
     System.exit(0);
              }
         }
    }
 
 

No comments:
Post a Comment