国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java環境中封裝多MIDIet程序

2019-11-18 13:12:35
字體:
來源:轉載
供稿:網友

  你可以將多個MIDIet程序存儲在一個JAR文件中。設備會自動顯示一個MIDIet的菜單,又用戶選擇運行哪個MIDIet程序。
  
  以下的例子中包含所有你所需要的: 兩個簡單MIDIet程序的源代碼,一個存儲在JAR文件中的表單文件(MANIFEST),一個java文件描述符文件(.jad),MIDIet的圖象文件(.png),還有一個用于運行MIDIet程序和編譯,預檢,創建JAR文件的DOS批處理文件。
  
  源代碼1:
  /*----------------------------------------------------
  * www.CoreJ2ME.com
  *
  * Simple MIDlet1
  *---------------------------------------------------*/
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  
  public class MIDlet1 extends MIDlet implements CommandListener
  {
  PRivate Display display; // Reference to Display object
  private TextBox tbxMain; // A Textbox to display a message
  private Command cmdExit; // A Command to exit the MIDlet
  
  // The constrUCtor
  public MIDlet1()
  {
  display = Display.getDisplay(this);
  
  cmdExit = new Command("Exit", Command.SCREEN, 1);
  
  tbxMain = new TextBox("Welcome", "Core J2ME", 50, 0);
  tbxMain.addCommand(cmdExit);
  tbxMain.setCommandListener(this);
  }
  
  // Called by application manager to start the MIDlet.
  public void startApp()
  {
  display.setCurrent(tbxMain);
  }
  
  // A required method
  public void pauseApp()
  { }
  
  // A required method
  public void destroyApp(boolean unconditional)
  { }
  
  // Check to see if our Exit command was selected
  public void commandAction(Command c, Displayable s)
  {
  if (c == cmdExit)
  {
  destroyApp(false);
  notifyDestroyed();
  }
  }
  }
  
  源代碼2:
  
  /*----------------------------------------------------
  * www.CoreJ2ME.com
  *
  * Simple MIDlet2
  *---------------------------------------------------*/
  
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  
  public class MIDlet2 extends MIDlet implements CommandListener
  {
  private Display display; // Reference to Display object
  private Form frmMain; // The main form
  private TextField txfName; // A text field to prompt for name
  private Command cmdExit; // A Command to exit the MIDlet
  
  // The constructor
  public MIDlet2()
  {
  display = Display.getDisplay(this);
  
  cmdExit = new Command("Exit", Command.SCREEN, 1);
  
  txfName = new TextField("Name:", "", 10, TextField.ANY);
  
  frmMain = new Form("Sample Form");
  frmMain.addCommand(cmdExit);
  frmMain.append(txfName);
  frmMain.setCommandListener(this);
  }
  
  // Called by application manager to start the MIDlet.
  public void startApp()
  {
  display.setCurrent(frmMain);
  }
  
  // A required method
  public void pauseApp()
  { }
  
  // A required method
  public void destroyApp(boolean unconditional)
  { }
  
  // Check to see if our Exit command was selected
  public void commandAction(Command c, Displayable s)
  {
  if (c == cmdExit)
  {
  destroyApp(false);
  notifyDestroyed();
  }
  }
  }
  
  ---------------------------------------------------
  
  mainfest.mf 文件(要存到JAR文件里):
  
  MIDlet-Name: TwoMIDlets
  MIDlet-Version: 1.0
  MIDlet-Vendor: Core J2ME Technology
  MIDlet-1: MIDlet1,/image1.png, MIDlet1
  MIDlet-2: MIDlet2,/image2.png, MIDlet2
  MicroEdition-Configuration: CLDC-1.0
  MicroEdition-Profile&: MIDP-1.0
  
  MIDlet.jad 文件
  
  MIDlet-Name: TwoMIDlets
  MIDlet-Version: 1.0
  MIDlet-Vendor: Core J2ME Technology
  MIDlet-Description: Packaging multiple MIDlets
  MIDlet-Jar-URL: MIDlet.jar
  MIDlet-Jar-Size: 3144
  MIDlet-1: MIDlet1,/image1.png, MIDlet1
  MIDlet-2: MIDlet2,/image2.png, MIDlet2
  --------------------------------------------------
  Emulator的顯示結果:
  從左向右:
  1。顯示MIDIet程序的菜單。
  2。運行MIDIet 1
  3。運行MIDIet 2
  
Java環境中封裝多MIDIet程序


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岳普湖县| 高青县| 五家渠市| 左权县| 河南省| 珲春市| 乌兰浩特市| 台中市| 定陶县| 旺苍县| 林甸县| 玉山县| 嵊州市| 右玉县| 布尔津县| 平江县| 通山县| 涟水县| 饶阳县| 新竹市| 托克托县| 澄江县| 固阳县| 杭锦后旗| 芜湖市| 开鲁县| 葵青区| 青海省| 德令哈市| 会宁县| 竹北市| 轮台县| 沐川县| 乡宁县| 庆阳市| 台山市| 正阳县| 古浪县| 陕西省| 牟定县| 长武县|