1 / 32

第 4 章  MIDP 高階使用者介面 應用設計

第 4 章  MIDP 高階使用者介面 應用設計. 課程內容簡報 4-1 建立 MIDlet 第一個程式 4-2 建立 MIDlet 生命週期循環 4-3 MIDP 高階使用者介面 4-4 Screen 類別四項子類別應用 4-5 Form 類別應用 4-6 結論. 4-1 建立 MIDlet 第一個程式. import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class helloMyFriend extends MIDlet {

major
Download Presentation

第 4 章  MIDP 高階使用者介面 應用設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第4章 MIDP高階使用者介面應用設計 課程內容簡報 4-1 建立MIDlet第一個程式 4-2 建立MIDlet生命週期循環 4-3 MIDP高階使用者介面 4-4 Screen類別四項子類別應用 4-5 Form類別應用 4-6 結論

  2. 4-1 建立MIDlet第一個程式 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class helloMyFriend extends MIDlet { Display display; Form form; public helloMyFriend(){ display=Display.getDisplay(this); form=new Form(“遊戲天地”); form.append(“歡迎光臨!遊戲製作世 界\n 朋友們快加入手機遊戲製作"); } public void startApp(){ display.setCurrent(form); } public void pauseApp(){} public void destroyApp(boolean unconditional){} }

  3. 4-2 建立MIDlet生命週期循環 • 程式架構中,設計程式之流程是包含完整生命週期。本循環週期是繼承自javax.microedition.midlet.MIDlet抽象類別。一個MIDlet設定類別經由這些介面來執行和控制應用管理軟體。其流程狀態與程式驗證如下:

  4. 程式表達MIDP架構實在不易,本範例使用按鍵來控制流程,MIDP架構也就是如此,相關的API方法概論如下:程式表達MIDP架構實在不易,本範例使用按鍵來控制流程,MIDP架構也就是如此,相關的API方法概論如下:

  5. 4-3 MIDP高階使用者介面 • 使用者介面是指裝置內的應用程式與使用者之間互動機制,因此,MIDlet事件處理中區分為高階與低階事件處理。

  6. Display與Displayable顯示元件類別: 1. 判斷手機是否支援彩色,true代表支援彩色顯示,false則否。 public boolean isColor(); 2. 判斷支援顏色數目多寡。 public int numColors(); 3. 取得目前MIDlet可視物件。 public Displayable getCurrent();

  7. 4. 要求不同的可視物件能在螢幕上顯示。 public void setCurrent (Displayable nextDisplayable); 5. 要求顯示目前的Alert物件與結束Alert物件後顯示下一個可視 物件。 public void setCurrent (Alert alert, Displayable nextDisplayable); 註:假定MIDlet執行前景有顯示F畫面和MIDlet執行顯示背景B畫面,當前景MIDlet呼叫getCurrent(),其會回傳F。當背景呼叫getCurrent(),則回傳B,如果要MIDlet改變目前的顯示狀態則呼叫setCurrent()。

  8. Command命令型態 :命令種類為規範所使用的命令意義,其定義8種命令型式。

  9. CommandListener設定才能加入Command按鍵,與執行Command所執行動作敘述。CommandListener設定才能加入Command按鍵,與執行Command所執行動作敘述。 1. 加入一個Command物件至顯示畫面。 public void addCommand (Command cmd); 2. 從顯示畫面移除一個Command物件。 public void removeCommand (Command cmd) ; 3. 設定Command到可視畫面,取代之前的CommandListener。 public void setCommandListener (CommandListener l); 4. 依照所指定的可視畫面來執行Command命令。 public void commandAction (Command c, Displayable d);

  10. 4-4 Screen類別四項子類別應用 • List類別:List類別是運用在顯示可視畫面中,其呼叫的 建構式有兩種應用方法 1. 建立一個新的、空的List,定義其標題和設定List類型。 public List (String title, int listType); 2. 延續前一個用法,並增加字串列陣和圖檔列陣加入至清單內 容。 public List (String title, int listType, String[] stringElements, Image[] imageElements);

  11. List類別物件中,listType所定參數為建立Choice類型中的List類別物件中,listType所定參數為建立Choice類型中的 三個常數:

  12. List類別還有許多操控可視畫面的應用方法: 1. 增加一個List元件。 public int append (String stringPart, Image imagePart); 2. 刪除由參考值elementNum的指定元件。 public void setCurrent (Alert alert, Displayable nextDisplayable); 3. 取得參考值elementNum的元件圖檔部份。 public Image getImage (int elementNum); 4. 取得參考值elementNum的元件字串部份。 public String getString(int elementNum) ;

  13. 5. 當元件被選擇取得布林函數值指示。 public boolean isSelected (int elementNum); 6. 插入一個選項至指定選項之前。 public void insert (int element, String stringPart, Image imagePart); 7. 參考elementNum元件來設定字串和圖檔部份,取代目前的選項部份。 public void set (int elementNum, String stringPart, Image imagePart) 8. 設定元件選取狀態。 public void setSelectedIndex (int elementNum, boolean selected) ; 9. 設定元件選取狀態。 public int size();

  14. Alert類別 :它的操控方法與一般Screen物件相同。 1. 建構一個新的、空的標題為title的Albert物件。 public Alert (String title); 2. 建構一個新的、空的標題為title、所要顯示訊息alertText、顯 示圖檔alertImage和Alert所提供的資料種類alertType之Albert 物件。 public Alert (String title, String alertText, Image alertImage, AertType alertType);

  15. Alert類別 :利用Display 類別的setCurrent()函式將設為的 Alert顯示在螢幕畫面裏。 1. 要求顯示設定的alert畫面,再回到下一個所設定的nextDisplayable 畫面。 public void setCurrent (Alert alert, Displayable nextDisplayable); 2. FOREVER指定Alert畫面保持到使用者要  求離開,其使 用參數值為setTimeout()。 public static final int FOREVER; 3. 取得顯示Alert畫面的時間,時間單位為千分之一秒。 public int getTimeout();

  16. 4 .取得顯示Alert畫面停留所定義的時間,其時間單位為千分之 一秒或是定義為modal類型的特別值FOREVER。 public int getDefaultTimeout(); 5. 設定Alert畫面顯示時間,其設定時間單位為千分之一秒或是 特別值FOREVER。 public void setTimeout(int time);

  17. Alert警告訊息還有其他相關的方法,可以提供給使用者Alert警告訊息還有其他相關的方法,可以提供給使用者   設定Alert畫面。 1. 設定在Alert畫面之文字字串。 public void setString(String str); 2. 取得在Alert畫面使用的文字字串。 public String getString(); 3. 設定圖檔顯示在Alert畫面 。 public void setImage (Image img);

  18. 4. 取得顯示在Alert畫面的圖檔。 public Image getImage (); 5. 設定Alert畫面的種類,這的AlertType為提供特別的應用種 類,請參考下面的敘述。 public void setType (AlertType type); 6. 取得Alert畫面的種類。 public AlertType getType ();

  19. AlertType類別提供自然的警告方式,這裏一共有五種警AlertType類別提供自然的警告方式,這裏一共有五種警 告音效來提供給使用者使用: 1. 提供非危險訊息給用戶,如簡單的潑濺聲就可以呼叫INFO音效。 public static final AlertType INFO; 2. 暗示使用者可能有潛在危險的告警音效,例如警告「操作者將 有可能會刪除資料狀態」的音效。 public static final AlertType WARNING; 3. 暗示使用者操作錯誤的警告音效,例如「記憶體不足無法執行 應用程式」的錯誤警告之音效。 public static final AlertType ERROR;

  20. 4. 暗示使用者預設要求要執行事件之警告音效,例如設定「五分 鐘後有會議」告知使用者的音效。 public static final AlertType ALARM; 5. 暗示使用者完成相關動作與操作事件的確認音效,例如告知已 經完成儲存檔案動作的音效。 public static final AlertType CONFIRMATION; 6. 在Alert中播放AlertType定義的音樂型態,其播放產生適當的聲音 給使用者,實際音效產生是由手機設備而來。 public boolean playSound (Display display);

  21. TextBox類別 :TextBox類別還有一些取得相關訊息之應用方法: 1. 設定TextBox內的文字內容,它可取代之前的文字內容。 public void setString (String text); 2. 取得TextBox內的文字內容。 public void getString (); 3. 從字元陣列(data)設定TextBox內容,取代之前內容,設定參數 offset為data字元中之索引值,同時設定長度為length。 public void setChars (char[] data, int offset, int length); 4. 取得TextBox的字元陣列data。 public int getChars (char[] data);

  22. 5.插入文字內容到TextBox內,將src文字插入至position位置內。5.插入文字內容到TextBox內,將src文字插入至position位置內。 public void insert (String src, int position); 6. 將字元陣列data,插入到position位置區域,設定長度為length。 public void insert (char[] data,int offset, int length, int position); 7. 以offset的參考值開始刪除,其刪除長度為length字元。 public void delete (int offset, int length); 8. 在TextBox內限定處理設定之最大長度。 public int setMaxSize (int maxSize); 9. 取得在TextBox內最大字元長度。 public int getMaxSize (); 10. 取得目前的TextBox內的字元數目。 public int size () ; 11. 取得目前編輯輸入位置。 public int getCarePosition ();

  23. TextFiled類別中所定義的一些設限的輸入常數所運用。TextFiled類別中所定義的一些設限的輸入常數所運用。 1. 允許輸入任何文字。 public static final int ANY; 2. 限制模式之參數值。 public static final int CONSTRAINT_MASK ; 3. 允許使用者輸入浮點數數值。 public static final int DECIMAL ; 4. 允許使用者輸入email字串使用。 public static final int EMAILADDR ; 5. 當文字編輯時指定文字狀態,每個句子第一字母為大寫。 public static final int INITIAL_CAPS_SENTENCE; 6. 當文字編輯時指定文字狀態,每個文字第一字母為大寫。 public static final int INITIAL_CAPS_WORD;

  24. 7. 指定文件輸入不是由文字組成 。 public static final int NON_PREDICTIVE; 8. 使用者只能輸入數字,同時包含正、負符號。 public static final int NUMERIC; 9. 當使用者輸入任何文字做為密碼時會,以*符號來顯示。 public static final int PASSWORD; 10. 使用者只能輸人電話號碼,其他文字則不行。 public static final int PHONENUMBER; 11. 指定文字輸入是重要文件。 public static final int SENSITIVE; 12. 指定編輯目前禁止部份。 public static final int UNEDITABLE; 13. 允許使用者輸入URL 。 public static final int URL;

  25. 4-5 Form類別應用 • Form類別:Form類別是Screen的子類別其中包含多個項目所組合而成。 1. 新增Item物件到Form裏。 public int append (Item item); 2. 新增Item物件字串到Form中。 public int append (String str); 3. 新增Item物件圖像到Form中。 public int append (Image img); 4. 插入一個Item物件到Form中 。 public void insert (int itemNum, Item item); 5. 由itemNum為參考值來刪除Item物件 。 public void delete (int itemNum); 6. 從Form刪除全部item物件 。 public void deleteAll ();

  26. 7. 參考itemNum數值設定Item物件取代之前的item。 public void set (int itemNum, Item item); 8. 依照itemNum參考值來取得Item物件位置。 public Item get (int itemNum); 9. 由Form設定一個itremStateListener,取代前一個itremStateListener。 public void setItemStateListener (ItemStateListener iListener); 10. 取得Form物件中的item物件數目。 public int size (); 11. 取得Item物件的標籤。 public String getLabel (); 12. 設定Item物件標籤,如果label是null時則Item中沒有label。 public void setLabel (String label); 13. 使用者已經改變Item內部狀態時所呼叫。 public void itemStateChanged (Item item);

  27. TextField類別應用:對Form而言TextField類別是建立一個編輯文字元件。TextField類別應用:對Form而言TextField類別是建立一個編輯文字元件。 1. 從TextField刪除字元。 public void delete (int offset, int length); 2. 取得目前輸入位置。 public int getCarePosition (); 3. 從字元陣列0開始複製TextField內容。 public int getChars (char[] data); 4. 取得目前輸入TextField限制。 public int getConstraints (); 5. 回傳可以儲存TextField最大字元。 public int getMaxSize (); 6. 取得TextField內容,以字串型態。 public String getString ();

  28. 7. 插入陣列字元到TextField內容。 public void insert (char[] data,int offset,int length,int position); 8. 插入字串到TextField內容。 public void insert (String src, int position); 9. 從字元陣列取代之前內容來設定textField內容。 public void setChars (char[] data, int offset,int length); 10. 設定輸入TextField限制。 public void setConstraints (int constraints); 11. 設定在TextField可以儲存最大字元數。 public int setMaxSize (int maxSize); 12. 使用text來設定TextField內容。 public void setString (String text); 13. 取得TextField目前字元數目。 public int size ();

  29. Image類別應用:Image類別應用是設計遊戲中的主要精髓骨幹 。 1. 建立一個不可修改之圖片。 public static Image createImage(byte[] imageData, int imageOffset, int imageLength); 2. 從來源圖檔建立一個不可修改的圖片。 public static Image createImage(Image source); 3. 在手機畫面上建立一個可以修改圖片。 public static Image createImag(int width, int height); 4. 從名稱來源解碼圖片資料,建立一個不可修改的圖片。 public static Image createImage(String name) throws IOException; 5. 建立一個新的Graphics物件表現圖檔狀態。 public Graphics getGraphics () ;

  30. ImageItem類別同樣也提供可運用的呼叫各項函式: 1. 建立一個新的ImageItem物件。 public ImageItem(String label,Image img,int layout,String altText); 2. 預設圖片放置。 public static final int LAYOUT_DEFAULT; 3. 將圖片置於靠左方向。 public static final int LAYOUT_LEFT ; 4. 將圖片置於靠右方向。 public static final int LAYOUT_RIGHT; 5. 將圖片置於置中方向。 public static final int LAYOUT_CENTER; 6. 將圖片所置於位子之前插入一個空白。 public static final int LAYOUT_NEWLINE_BEFORE; 7. 將圖片所置於位子之後插入一個空白。 public static final int LAYOUT_NEWLINE_AFTER;

  31. Image類別用法,Form表單的應用也可以放置圖檔應用。Image類別用法,Form表單的應用也可以放置圖檔應用。 1. 當圖片超過顯示範圍時,則以文字代替圖片來顯示。 public String getAltText (); 2. 取得在ImageItem內所包含的圖片。 public Image getImage (); 3. 取得圖片置放的狀況。 public int getLayout (); 4. 設定ImageItem的文字字串。 public void setAltText (String text); 5. 在IamgeItem內所包含設定圖片物件。 public void setImage (Image img); 6. 設定置於位置狀態。 public void setLayout (int layout);

  32. 4-6 結論 • 高階使用者介面對遊戲可應用方法不多,主要是配合遊戲需要表達選項的製作。不過相關排版方法也可以由其他方式來代替 : 1. 高階應用選擇遊戲方式: 2. 低階應用選擇遊戲方式:

More Related