import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class DateField1 extends MIDlet implements CommandListener
{
   private Display display;
   private Form f1;
   private Form f2;
   private DateField date;
   private DateField time;

   private Command okCommand;
   private Command exitCommand;
   private Command backCommand;

   public DateField1()
   {
      display = Display.getDisplay(this);
      date = new DateField("Date", DateField.DATE);
      time = new DateField("Time", DateField.TIME);
      f1 = new Form("Date and time");

      okCommand = new Command("Ok", Command.SCREEN, 0);
      exitCommand = new Command("Exit", Command.EXIT, 0);
      backCommand = new Command("Back", Command.BACK, 0);
   }

   public void startApp()
   {

      f1.append(date);
      f1.append(time);

      f1.addCommand(okCommand);
      f1.addCommand(exitCommand);
      f1.setCommandListener(this);
      display.setCurrent(f1);
   }

   public void pauseApp(){}
   public void destroyApp(boolean b){}

   public void commandAction(Command c, Displayable s)
   {
      if(c == okCommand)
      {
         f2 = new Form("Date and time");

         Calendar cal = Calendar.getInstance();
         Date datex = date.getDate();
         cal.setTime(datex);

         String text = "Date: " + cal.get(Calendar.DATE) + "." +
                                  cal.get(Calendar.MONTH) + "." +
                                  cal.get(Calendar.YEAR);
         cal.setTime(time.getDate());
         text = text + "\ntime: " + cal.get(Calendar.HOUR) + ":" +
                                  + cal.get(Calendar.MINUTE);
         f2.append(text);
         f2.addCommand(backCommand);
         f2.setCommandListener(this);
         display.setCurrent(f2);

      }else if(c == exitCommand)
      {
         destroyApp(false);
         notifyDestroyed();
      }else if(c == backCommand)
      {
         display.setCurrent(f1);
      }
   }
}

