Sunday, November 3, 2013

phone application

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.*;

public class Myph extends MIDlet implements CommandListener{
   
    private Form fm;
    private List lst;
    private TextBox tb;
    private Command exit,send,back,call,contacts,message;
    private Display d;
    public Myph()
    {
        d=Display.getDisplay(this);
        fm=new Form("my phone");
        tb=new TextBox("message Box",null,500,0);//500 characters can be text
        lst=new List("contacts",List.IMPLICIT);
        lst.append("mom 98491",null);
        lst.append("dad 9900...",null);
        lst.append("bro 888..",null);
        lst.append("rajendra 9849186838",null);
        exit=new Command("Exit", Command.EXIT,1);
        back=new Command("Back", Command.BACK,1);
        send=new Command("Send", Command.OK,1);
        call=new Command("Call", Command.OK,1);
        message=new Command("Mesaage Box", Command.OK,2);
        contacts=new Command("Contacts List", Command.OK,1);
       
        fm.addCommand(exit);
        fm.addCommand(message);
        fm.addCommand(contacts);
        tb.addCommand(back);
        tb.addCommand(send);
        lst.addCommand(call);
      //  tb.addCommand(call);//call option is not visible
        fm.setCommandListener(this);
        tb.setCommandListener(this);
        lst.setCommandListener(this);
         }
   
   
    public void startApp() {
        d.setCurrent(fm);
       
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable dd) {
        if(c==exit)
        {
            destroyApp(false);
            notifyDestroyed();
           
        }
        else if(c==contacts)
        {
            Alert al=new Alert("welcome");
            al.setString("keep in touch with your dear ones");
            d.setCurrent(al,lst);
             
        }
        else if(c==message)
        {
            Alert al=new Alert("welcome");
            al.setString("Happy messaging");
            al.setType(AlertType.INFO);
           
            d.setCurrent(al,tb);
        }
        else if(c==back)
        {
            d.setCurrent(fm);
        }
        else if(c==send)
        {
            Alert al=new Alert("Messaging Service");
            al.setString("msg is sent successfully");
            al.setType(AlertType.INFO);
            d.setCurrent(al,fm);
        }
        else if(c==call)
        {
            Alert al=new Alert("calling..");
            al.setString("No networking coverage");
            al.setType(AlertType.INFO);
          //  al.setType(AlertType.ERROR);
           // d.setCurrent(al,tb);//it will go msg box
            d.setCurrent(al,fm);
           
        }
    }
}

No comments:

Post a Comment