熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

Java環境中封裝多MIDIet程序

2013-11-15 11:50:09  來源: JSP教程 

  你可以將多個MIDIet程序存儲在一個JAR文件中設備會自動顯示一個MIDIet的菜單又用戶選擇運行哪個MIDIet程序
  
  以下的例子中包含所有你所需要的 兩個簡單MIDIet程序的源代碼一個存儲在JAR文件中的表單文件(MANIFEST)一個JAVA文件描述符文件(jad)MIDIet的圖象文件(png)還有一個用於運行MIDIet程序和編譯預檢創建JAR文件的DOS批處理文件
  
  源代碼
  /*
  *
  *
  * Simple MIDlet
  **/
  import javaxmicroeditionmidlet*;
  import javaxmicroeditionlcdui*;
  
  public class MIDlet 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 MIDlet()
  {
  display = DisplaygetDisplay(this);
  
  cmdExit = new Command(Exit CommandSCREEN );
  
  tbxMain = new TextBox(Welcome Core JME );
  tbxMainaddCommand(cmdExit);
  tbxMainsetCommandListener(this);
  }
  
  // Called by application manager to start the MIDlet
  public void startApp()
  {
  displaysetCurrent(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();
  }
  }
  }
  
  源代碼
  
  /*
  *
  *
  * Simple MIDlet
  **/
  
  import javaxmicroeditionmidlet*;
  import javaxmicroeditionlcdui*;
  
  public class MIDlet 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 MIDlet()
  {
  display = DisplaygetDisplay(this);
  
  cmdExit = new Command(Exit CommandSCREEN );
  
  txfName = new TextField(Name: TextFieldANY);
  
  frmMain = new Form(Sample Form);
  frmMainaddCommand(cmdExit);
  frmMainappend(txfName);
  frmMainsetCommandListener(this);
  }
  
  // Called by application manager to start the MIDlet
  public void startApp()
  {
  displaysetCurrent(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();
  }
  }
  }
  
  
  
  mainfestmf 文件(要存到JAR文件裡)
  
  MIDletName: TwoMIDlets
  MIDletVersion:
  MIDletVendor: Core JME Technology
  MIDlet: MIDlet/imagepng MIDlet
  MIDlet: MIDlet/imagepng MIDlet
  MicroEditionConfiguration: CLDC
  MicroEditionProfile&: MIDP
  
  MIDletjad 文件
  
  MIDletName: TwoMIDlets
  MIDletVersion:
  MIDletVendor: Core JME Technology
  MIDletDescription: Packaging multiple MIDlets
  MIDletJarURL: MIDletjar
  MIDletJarSize:
  MIDlet: MIDlet/imagepng MIDlet
  MIDlet: MIDlet/imagepng MIDlet
  
  Emulator的顯示結果
  從左向右
  顯示MIDIet程序的菜單
  運行MIDIet
  運行MIDIet
  


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19725.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.