import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.*;
public class TestDemo extends MIDlet implements CommandListener{
private Display d;
private Form f;
private Command ce,cp;
private TextField phTe;
private Date
d1;
private
DateField df;
//private
Calendar cr;
private
Alert a1;
public
void startApp(){
d
= Display.getDisplay(this);
f = new Form("Test");
df = new DateField("Day",DateField.DATE);
phTe = new TextField("Phone","",12,TextField.PHONENUMBER);
ce = new Command("EXIT",Command.EXIT,1);
cp = new Command("VALIDATE",Command.ITEM,1);
//cr = Calendar.getInstance();
//System.out.println("
"+cr);
d1
= new Date();
df.setDate(d1);
f.append(df);
//f.append(cr);
f.append("Helllo how are you");
f.append(phTe);
f.addCommand(ce);
f.addCommand(cp);
f.setCommandListener(this);
d.setCurrent(f);
}
public void pauseApp(){}
public void destroyApp(boolean
unconditional){}
public
void commandAction(Command c,Displayable s){
if( c == ce)
notifyDestroyed();
else if(c == cp){
String pstr = phTe.getString();
String astr = pstr.substring(0,3);
if(pstr.substring(0,4).equals("0400")){
//a1 = new Alert("valid",pstr.substring(0,4)+"
valid area code",null,AlertType.INFO);
//a1.setTimeout(1000);
//d.setCurrent(a1,f);
}else
if((astr.equals("040"))||(astr.equals("041"))||(astr.equals("050"))||(astr.equals("044"))){
//String msg = astr+"
is a valid area code";
//a1 = new Alert("valid",msg,null,AlertType.INFO);
//a1.setTimeout(1000);
//d.setCurrent(a1,f);
// System.out.println(" "+f.get(f.size()-1).getClass().getName());
if(f.get(f.size()-1).getClass().getName().equals("javax.microedition.lcdui.StringItem")){
f.delete(f.size()-1);
f.append("good one");}
else
f.append("good");
}else{
String msg = astr+" is not
a valid area code, please enter a valid phone number";
a1 = new Alert("valid",msg,null,AlertType.INFO);
a1.setTimeout(5000);
phTe.setString("");
d.setCurrent(a1,f);
}
}
}
}