<source id="4vppl"><ins id="4vppl"></ins></source>
<u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
<object id="4vppl"></object>
  • <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

    <object id="4vppl"></object>
    <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

      <i id="4vppl"><thead id="4vppl"></thead></i>

      <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>

      當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > 用一個簡單的例子來看MIDlet的生命周期原文

      用一個簡單的例子來看MIDlet的生命周期原文
      2010-01-13 23:30:05  作者:  來源:

      用一個簡單的例子來看MIDlet 的生命周期

      想來估計也沒有比網上教程說的更清楚了,我這里摘錄的只是文字,從www.j2medev.com來獲取,更詳細的資料可以到www.j2medev.com上查看。我將會以一個例子跟查看官方的源代碼來分析它們。

      理解J2ME 的體系結構并不像想象的那么容易,我們覺得讀更多的資料幫助也不大,我們

      直接邁向J2ME 開發也許會對你理解J2ME 平臺體系結構這個重要的概念有所幫助。在MIDP

      中定義了一種新的應用程序模型MIDlet,它是被Application Management Software(AMS)管理

      的。AMS 負責MIDlet 的安裝、下載、運行和刪除等操作。在被AMS 管理的同時,MIDlet 可

      以和應用管理軟件通信通知應用管理軟件自己狀態的變化,通常是通過方法notifyDestroyed()

      和notifyPaused()實現的

      MIDlet 有三個狀態,分別是pause、active 和destroyed。在啟動一個MIDlet 的時候,應用

      管理軟件會首先創建一個MIDlet 實例并使得他處于pause 狀態,當startApp()方法被調用的時候

      MIDlet 進入active 狀態,也就是所說的運行狀態。在active 狀態調用destroyApp(boolean

      第1 章 J2ME 技術概述

      4

      unconditional)或者pauseApp()方法可以使得MIDlet 進入destroyed 或者pause 狀態。值得一提的

      是destroyApp(boolean unconditional)方法,事實上,當destroyApp()方法被調用的時候,AMS 通

      知MIDlet 進入destroyed 狀態。在destroyed 狀態的MIDlet 必須釋放了所有的資源,并且保存了

      數據。如果unconditional 為false 的時候, MIDlet 可以在接到通知后拋出

      MIDletStateChangeException 而保持在當前狀態,如果設置為true 的話,則必須立即進入destroyed

      狀態。下圖說明了MIDlet 狀態改變情況:

      <!--[if !vml]--><!--[endif]-->

       


      看看我那個簡單的例子
      public class HelloWorld extends MIDlet ......{

          public HelloWorld() ......{ 
              System.out.println("這個是程序的構造函數,程序運行的時候首先調用這個");
          }

          protected void destroyApp(boolean unconditional)
                  throws MIDletStateChangeException ......{
              System.out.println("這個是程序的destroyed事件,當您按下退出時調用");
          }

          protected void pauseApp() ......{
              System.out.println("這個是程序的pause事件,當您按下暫停的時調用");

          }

          protected void startApp() throws MIDletStateChangeException ......{
              System.out.println("這個是程序的active事件,程序啟動時候調用");

          }

      }

      大家可以運行程序中看到這個程序的運行先后順些。基本上就明白了程序的調用機制了。
      現在大家思考下,j2me的MIDlet是怎么樣運行的呢?sun在里面進行了什么樣子的限制與手腳呢?
      一般的應用程序都有個main入門。這里沒有,為什么呢?
      我想這個就是ASM的作用了,sun在后臺做了很多處理,比如包括,啟動容器,啟動MIDlet相關的資源等等。

      public static void main(String args[]) ...{
              CommandState state = new CommandState();

          /**//*
           * pass resource strings down to the native system menu and
           * popup choice group methods...
           */
          initSystemLabels();

              /**//*
               * We will try to handle any printing at this level, because
               * displaying JAM command line errors is device specific.
               */
              try ...{
                  initializeInternalSecurity();

              /**//* Start a inbound connection watcher thread. */
              new Thread(new PushRegistryImpl()).start();

                  restoreCommandState(state);

                  // handle any development machine only functions at this level
                  switch (state.nextCommand) ...{
                  case CommandProcessor.RUN_CLASS:
                      runLocalClass(state);
                      state.nextCommand = CommandProcessor.EXIT;
                      break;

                  case CommandProcessor.MANAGE:
                      manage(state);
                      break;

                  case CommandProcessor.LIST:
                  case CommandProcessor.STORAGE_NAMES:
                      list(state);
                      state.nextCommand = CommandProcessor.EXIT;
                      break;

                  case CommandProcessor.REMOVE:
                      if (DEV_STORAGE_NAME.equals(state.suiteStorageName)) ...{
                          removeDevStorage(state);
                          state.nextCommand = CommandProcessor.EXIT;
                          break;
                      }

                      // fall through
                  default:
                      CommandProcessor.perform(state);
                      if (state.status == CommandProcessor.MIDLET_SUITE_NOT_FOUND) ...{
                          System.out.println("The MIDlet suite was not found.");
                      } else if (state.initialCommand == CommandProcessor.INSTALL &&
                              state.status == CommandProcessor.OK) ...{
                          System.out.println("Storage name: " +
                                             state.suiteStorageName);
                      }
                  }
              } catch (InvalidJadException ije) ...{
                  System.out.println("** Error installing suite (" +
                                     ije.getReason() + "): " + 
                                     messageForInvalidJadException(ije));
              } catch (IOException ioe) ...{
                  System.out.println("** Error installing suite: " +
                                     ioe.getMessage());
              } catch (ClassNotFoundException ex) ...{
                  if (state.initialCommand == CommandProcessor.MANAGE) ...{

                    state.runExceptionMessage =
                          Resource.getString("The application cannot be launched. " +
                          "One of the application classes appears to be missing. " +
                          "This could be due to a mis-named class. Contact the " +
                          "application provider to resolve the issue.");
                  } else ...{
                      System.out.println("MIDlet class(s) not found: " + 
                                         ex.getMessage());
                  }
              } catch (InstantiationException ex) ...{
                  if (state.initialCommand == CommandProcessor.MANAGE) ...{
                     state.runExceptionMessage = Resource.getString(
                         "The application cannot be launched. The application " +
                         "may have done an illegal operation. Contact the " +
                         "application provider to resolve the issue.") + " " +
                         ex.getMessage();
                  } else ...{
                      System.out.println(
                          "MIDlet instance(s) could not be created: " + 
                                       ex.getMessage());
                  }
              } catch (IllegalAccessException ex) ...{
                  if (state.initialCommand == CommandProcessor.MANAGE) ...{
                      state.runExceptionMessage = Resource.getString(
                         "The application cannot be launched. The application " +
                         "may have done an illegal operation. Contact the " +
                         "application provider to resolve the issue.") + " " +
                         ex.getMessage();
                  } else ...{
                      System.out.println(
                          "MIDlet class(s) could not be accessed: " + 
                          ex.getMessage());
                  }
              } catch (OutOfMemoryError ex) ...{
                  if (state.initialCommand == CommandProcessor.MANAGE) ...{
                      state.runExceptionMessage = Resource.getString(
                          "The application has unexpectedly quit because it ran " +
                          "out of memory.");
                  } else ...{
                      System.out.println("The MIDlet has run out of memory");
         &nb

      安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
      国产午夜福三级在线播放_亚洲精品成a人片在线观看_亚洲自慰一区二区三区_久久棈精品久久久久久噜噜
      <source id="4vppl"><ins id="4vppl"></ins></source>
      <u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
      <object id="4vppl"></object>
    1. <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

      <object id="4vppl"></object>
      <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

        <i id="4vppl"><thead id="4vppl"></thead></i>

        <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>
        亚洲综合一区国产系列 | 亚洲日韩国产欧美综合一区 | 日韩25区中文字幕 | 亚洲人成网站在线在线观看 | 亚洲日韩性爱在线 | 专区在线观看中文字幕AV |