import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.Calendar;
import java.util.TimeZone;

public class LABHelloMIDlet3
        extends MIDlet
        implements CommandListener, ItemCommandListener {
    private Form mMainForm;
    private StringItem sItem, dItem;
    private TextField eItem, pItem;
    private Command exit, print, printItem;

    public LABHelloMIDlet3() {
        mMainForm = new Form("LABHelloMIDlet3");
        sItem = new StringItem(null, "Hello Students", StringItem.BUTTON);
        dItem = new StringItem(null, "Current Date & Time " );
        eItem = new TextField("email", null, 20, TextField.EMAILADDR);
        pItem = new TextField("password", null, 20, TextField.PASSWORD);
    }

    public void startApp() {
        mMainForm.append(sItem);
        sItem.setLayout(Item.LAYOUT_2 | Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_AFTER);
        mMainForm.append(dItem);
        dItem.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_AFTER);

        TimeZone tz = TimeZone.getTimeZone("Italy/Rome");
	    Calendar cd = Calendar.getInstance();
	    cd.setTimeZone(tz);
		cd.setTime(new Date());

        mMainForm.append(new StringItem(null, ""+cd.getTime()));
        mMainForm.append(new StringItem(null, "Number of colors is " + Display.getDisplay(this).numColors()));
        mMainForm.append(eItem);
        mMainForm.append(pItem);

        exit = new Command("Exit", Command.EXIT, 0);
        print = new Command("Print", Command.SCREEN, 0);
        printItem = new Command("Print Item", Command.ITEM, 0);


        mMainForm.addCommand(exit);
        mMainForm.addCommand(print);

        //if you add a command to the item then the button appearence is shown
       sItem.setDefaultCommand(printItem);
       sItem.setItemCommandListener(this);
       mMainForm.setCommandListener(this);
       
        
        Display.getDisplay(this).setCurrent(mMainForm);
    }

    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void commandAction(Command c, Displayable s) {
        if (c == print) {
             mMainForm.deleteAll();
             mMainForm.append(eItem.getString()+"\n");
             mMainForm.append(pItem.getString());
             mMainForm.removeCommand(print);
        }
        else
        notifyDestroyed();
    }

     public void commandAction(Command c, Item i) {
      mMainForm.deleteAll();
             mMainForm.append(sItem.getText()+"\n");
             mMainForm.removeCommand(print);

     }
}
