張生工作室

          一切皆有可能

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            24 隨筆 :: 3 文章 :: 11 評論 :: 0 Trackbacks

          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.Item;
          import javax.microedition.lcdui.ItemStateListener;
          import javax.microedition.lcdui.TextField;
          import javax.microedition.midlet.MIDlet;
          import javax.microedition.midlet.MIDletStateChangeException;


          public class MessageMIDlet extends MIDlet {

           
           private welcome wcfrm=null;
           
           public MessageMIDlet() {

           }

           protected void destroyApp(boolean arg0) throws MIDletStateChangeException {


           }

           protected void pauseApp() {
           

           }

           protected void startApp() throws MIDletStateChangeException {
           
            wcfrm=new welcome(this);
            Display.getDisplay(this).setCurrent(wcfrm);
           }

          }

          class welcome extends Form implements CommandListener
          {

           
              private Command cmdExit=null;
              private Command cmdWrite=null;
              private writemsg wrfrm=null;
              private MIDlet let=null;
             
              public welcome(MIDlet mlet)
              {
               super("歡迎使用本程序");
               let=mlet;
           
               cmdExit=new Command("退出",Command.EXIT,1);
               cmdWrite=new Command("寫短信",Command.SCREEN,1);
               this.addCommand(cmdExit);
               this.addCommand(cmdWrite);
               this.setCommandListener(this);
               
              }
           public void commandAction(Command c, Displayable d) {
           
             if(c==cmdExit)
             {
            
              let.notifyDestroyed();
             }
             else
              if(c==cmdWrite)
              {
               wrfrm=new writemsg(let);
               Display.getDisplay(let).setCurrent(wrfrm);
             
              
              }
           
           }

          }
          class writemsg extends javax.microedition.lcdui.Form implements CommandListener,ItemStateListener
          {
           

           private Command cmdBack=null;
           private Command cmdwrNum=null;
           private MIDlet let=null;
           private TextField tf=null;
           private Command cmdDel=null;
           private writeNum2 wrnum=null;
           
           

           public writemsg(MIDlet mlet)
           {
           
            super("請輸入短信內容");
            let=mlet;
            cmdBack=new Command("返回",Command.EXIT,1);
            cmdwrNum=new Command("發送",Command.SCREEN,1);
            cmdDel=new Command("刪除",Command.EXIT,1);
            this.addCommand(cmdBack);
            this.addCommand(cmdwrNum);
           
            tf= new  TextField("","",255,TextField.ANY);
            //tf.addCommand(cmdDel);
            this.append(tf);
            this.setItemStateListener(this);
            this.setCommandListener(this);
            tf.setLayout(TextField.LAYOUT_VEXPAND);
           }
           
           public void commandAction(Command c, Displayable d) {
           
            if(c==cmdBack)
            {
             Display.getDisplay(let).setCurrent(new welcome(let));
            
            }else if(c==cmdwrNum)
            {
            wrnum=new  writeNum2(let);
             Display.getDisplay(let).setCurrent(wrnum);
            
            }else if(c==cmdDel)
            {
             int p=tf.getCaretPosition();
             if(p>0)
             {
              tf.delete(p-1, 1);
             }
             if(tf.getString().length()==0)
             {
                this.removeCommand(cmdDel);
                this.addCommand(cmdBack);
             
             }
            
            }

           
           }

           public void itemStateChanged(Item i) {
           
            if(i==tf)
            {
              if( tf.getString().length()>0)
              {
              // this.addCommand(cmdDel);
               this.removeCommand(cmdBack);
               this.addCommand(cmdDel);
              }
              else
              {
               this.removeCommand(cmdDel);
               this.addCommand(cmdBack);
              }
            
            
            }
           
           
           }
           
           
          }

           

          class writeNum2 extends javax.microedition.lcdui.Form implements CommandListener,ItemStateListener
          {
           

           private Command cmdBack=null;
           private Command cmdwrNum=null;
           private MIDlet let=null;
           private TextField tf=null;
           private Command cmdDel=null;
           private Form preFrm=null;
           private boolean sendflag=false;

           
           

           public writeNum2(MIDlet mlet)
           {
           
            super("請輸入對方號碼");
            let=mlet;
            preFrm=(Form) Display.getDisplay(let).getCurrent();
            cmdBack=new Command("返回",Command.EXIT,1);
            cmdwrNum=new Command("發送",Command.SCREEN,1);
            cmdDel=new Command("刪除",Command.EXIT,1);
            this.addCommand(cmdBack);
            this.addCommand(cmdwrNum);
           
            tf= new  TextField("","",13,TextField.NUMERIC);
            //tf.addCommand(cmdDel);
            this.append(tf);
            this.setItemStateListener(this);
            this.setCommandListener(this);
           
           }
           
           public void commandAction(Command c, Displayable d) {
           
            if(c==cmdBack)
            {
            if (sendflag)
            Display.getDisplay(let).setCurrent(new welcome(let));
            else
             Display.getDisplay(let).setCurrent(this.preFrm);
            
            }else if(c==cmdwrNum)
            {

              String msg= ((TextField)(preFrm.get(0))).getString();
              String phonenum= tf.getString();
             
              this.append("信息內容:"+ msg);
              this.append("發送號碼:"+ phonenum);
              this.append("發送狀態:成功");
              this.delete(0);
              this.removeCommand(cmdwrNum);
              this.removeCommand(cmdDel);
              this.addCommand(cmdBack);
              sendflag=true;
            }else if(c==cmdDel)
            {
             int p=tf.getCaretPosition();
             if(p>0)
             {
              tf.delete(p-1, 1);
             }
             if(tf.getString().length()==0)
             {
                this.removeCommand(cmdDel);
                this.addCommand(cmdBack);
             
             }
            
            }

           
           }


           public void itemStateChanged(Item i) {
           
            if(i==tf)
            {
              if( tf.getString().length()>0)
              {
              // this.addCommand(cmdDel);
               this.removeCommand(cmdBack);
               this.addCommand(cmdDel);
              }
              else
              {
               this.removeCommand(cmdDel);
               this.addCommand(cmdBack);
              }
            
            
            }
           
           
           }
           
           
          }

          /*

          class writeNum extends Form implements CommandListener
          {

           private MIDlet let=null;
           private Command cmdSend=null;
           private Command cmdBack=null;
           private TextField num=null;
           private Form backfrm=null;
           public writeNum(MIDlet mlet) {
           
            super("請輸入要發送的號碼");
            let=mlet;
            num=new TextField("","",13,TextField.NUMERIC);
            this.append(num);
            cmdSend=new Command("發送",Command.OK,1);
            cmdBack=new Command("返回",Command.BACK,1);
            this.addCommand(cmdSend);
            this.addCommand(cmdBack);
            this.backfrm=(Form) Display.getDisplay(let).getCurrent();
            this.setCommandListener(this);
           
           
           }

           public void commandAction(Command c, Displayable d) {
            if(c==cmdSend)
            {
             try
             {
              String msg=((TextField)this.backfrm.get(0)).getString();//當跨幾個Form時應該怎么辦?
              this.append("信息:"+ msg+"已發送到:"+ num.getString());
            
             this.delete(0);
             this.setTitle("信息已發送成功");
             }
             catch(Exception e)
             {
              this.append("信息成功發送");
             }
            }
            else if(c==cmdBack)
            {
             Display.getDisplay(let).setCurrent(this.backfrm);
            }
           
           
           }
           
          }
          **/

           



          張生工作室
          posted on 2008-11-28 13:06 張生工作室 閱讀(386) 評論(1)  編輯  收藏

          評論

          # re: j2me模擬短信 2009-09-19 19:47 15170987588
          我同意  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 阿克陶县| 益阳市| 昌宁县| 宁海县| 大兴区| 拉孜县| 峡江县| 凯里市| 瓮安县| 北宁市| 安达市| 蚌埠市| 闽侯县| 东源县| 祁东县| 汝城县| 德安县| 如东县| 哈密市| 雷山县| 闸北区| 且末县| 精河县| 全南县| 巩留县| 汤阴县| 轮台县| 淮安市| 黑水县| 襄汾县| 桐城市| 成都市| 晋州市| 松原市| 汉寿县| 思南县| 陕西省| 华宁县| 施秉县| 大埔县| 浦北县|