import javax.microedition.midlet.*; 
import javax.microedition.lcdui.*; 



public class Search extends MIDlet implements CommandListener
{ 
 Display display;
 TextBox box = null; 
 TextField tf ;
 List mainList;
 Form form ;
 String []words= {"E?? C??? C????? C?????(1)","C???I ??? ?E C??C????(2)","C????? C????? (3)","?C?? ??? C?I??(4)","C?C? ??EI ?C?C? ??E???(5)","C?I?C C???C? C???E???(6)"
 ," ??C? C????? C???E ????? U?? C??U??E ????? ??C C??C??? (7)"};
 Form fr;
 int ma = 0;
 String temp;
 String m ;
List subList;
List subList2;
 Alert a ;
 Command cmdExit = new Command("Exit", Command.EXIT, 0);
 Command ok = new Command("Search ",Command.EXIT ,1);
 Command back=  new Command("Back", Command.BACK ,2);
 Command delet= new Command("Delete",Command.EXIT ,3);
 
 public Search()
  {
   display = Display.getDisplay(this);
  mainList = new List("Main List",List.IMPLICIT);
   a = new Alert("Info Nothing");
   fr = new Form("C??CE?");
  }
 
public void SearchFormWo()
  {
   form =new Form("Search about Word");
   tf =new TextField("CII? C????? ","",100, TextField.ANY);
   form.append(tf);
   form.addCommand(ok);
   form.addCommand(back);
   form.setCommandListener(this);
   display.setCurrent(form);
}
 public void SearchFormNo()
  {
   form =new Form("Search about Word");
   tf =new TextField("CII? ??? C?C??","",100, TextField.PHONENUMBER);
   form.append(tf);
   form.addCommand(ok);
   form.addCommand(back);
   form.setCommandListener(this);
   display.setCurrent(form);
}
public void startApp()
{


mainList.append("E?E ?? ????",null);
   mainList.append("E?E ?? C??",null);
   mainList.addCommand(cmdExit);
   mainList.setCommandListener(this);
   display.setCurrent(mainList);	

}
public void pauseApp() {   } 

public void destroyApp(boolean unconditional) { notifyDestroyed();} 

/*The Words */
public void Search(String word)
{
	
temp="";



for(int i = 0;i<words.length;i++)
{
if(words[i].indexOf(word)>=0)
{
 temp +=words[i]+"\n"; //??C ???U C????E C?E? EE?E ???C

 ma = ma +1;//??C ??I ?? ??E ??E ??? C????E
}
}
}



public void commandAction(Command c, Displayable s) 
{ 
  if (c == cmdExit) 
  { 
    destroyApp(false); 
    notifyDestroyed(); 
  }
  else if ( c == List.SELECT_COMMAND )
        if ( mainList.getSelectedIndex() == 0 )
         {
           subList = new List("C?E?E ?? ????", List.IMPLICIT);
           
           SearchFormWo();
           
          }
          if (mainList.getSelectedIndex() == 1)
        {
          subList2 = new List("C?E?E ?? C??",List.IMPLICIT);
          SearchFormNo();
          
          }
  else if(c==ok)
  {
    m = tf.getString();
 Search(m);
if(temp.equals("")){
                 a.setString("not found");
                    a.setTimeout(2000);
                       display.setCurrent(a);
             }
else     { 

         fr.append(temp); 
        fr.append(ma+"???");
         fr.addCommand(back);
         fr.addCommand(delet);
     
     fr.setCommandListener(this);
     display.setCurrent(fr);
     
         }
  }
  if(c==back){mainList.setCommandListener(this);
         display.setCurrent(mainList);}
  if(c==delet){fr.delete(0);}
 /* if(c== delet){deleteForm();
             temp ="";
    ma = 0;
             display.setCurrent(fr);}
 }

public void deleteForm()
{
//l.deleteAll(); // only in MIDP 2.0
// to make this in MIDP 1.0
while (fr.size()>0) 
{
   fr.delete(0);
}
}*/
}} 
 

 
