ShowScreen.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:3k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.midlet.*; 
  2. import javax.microedition.lcdui.*; 
  3. public class ShowScreen extends MIDlet implements CommandListener{ 
  4.         private Display display; 
  5.         private Form props; 
  6.    
  7.   private Command backCommand = new Command("BACK", Command.BACK, 2); 
  8.   private Command cancelCommand = new Command("CANCEL", Command.CANCEL,1); 
  9.   private Command exitCommand = new Command("EXIT", Command.EXIT, 1); 
  10.   private Command helpCommand = new Command("HELP", Command.HELP, 1); 
  11.   private Command itemCommand = new Command("ITEM", Command.ITEM, 1); 
  12.   private Command okCommand = new Command("OK", Command.OK, 1); 
  13.   private Command screenCommand = new Command("SCREEN", Command.SCREEN,1); 
  14.   private Command stopCommand = new Command("STOP", Command.STOP, 1); 
  15.         public ShowScreen(){ 
  16.                 display = Display.getDisplay(this); 
  17.          } 
  18.         public void startApp() { 
  19.                 props = new Form("Hello World"); 
  20.                 props.append("Hello World!n"); 
  21.                 props.addCommand(backCommand); 
  22.                 props.addCommand(cancelCommand); 
  23.                 props.addCommand(exitCommand); 
  24.                 props.addCommand(helpCommand); 
  25.                 props.addCommand(itemCommand); 
  26.                 props.addCommand(okCommand); 
  27.                 props.addCommand(screenCommand); 
  28.                 props.addCommand(stopCommand); 
  29.                 props.setCommandListener(this); 
  30.                 display.setCurrent(props); 
  31.          } 
  32.         public void showScreen(String cmd) { 
  33.                 Form form=new Form("show cmd"); 
  34.                 form.append(cmd); 
  35.                 form.addCommand(exitCommand); 
  36.                 form.setCommandListener(this); 
  37.                 display.setCurrent(form); 
  38.          
  39.         } 
  40.         public void commandAction(Command c, Displayable s){ 
  41.                 if (c == exitCommand)
  42.                 { 
  43.                         destroyApp(false); 
  44.                     notifyDestroyed(); 
  45.                 }        
  46.                 else if(c==helpCommand) 
  47.                 { 
  48.                         showScreen("help"); 
  49.                 } 
  50.                 else if(c==backCommand) 
  51.                 { 
  52.                         showScreen("back"); 
  53.                 } 
  54.                 else if(c==cancelCommand) 
  55.                 { 
  56.                         showScreen("cancel"); 
  57.                 } 
  58.                 else if(c==itemCommand) 
  59.                 { 
  60.                         showScreen("item"); 
  61.                 } 
  62.                 else if(c==okCommand) 
  63.                 { 
  64.                         showScreen("ok"); 
  65.                 } 
  66.                 else if(c==screenCommand) 
  67.                 { 
  68.                         showScreen("screen"); 
  69.                 } 
  70.                 if(c==stopCommand) 
  71.                 { 
  72.                         showScreen("stop"); 
  73.                 } 
  74.          } 
  75.         public void destroyApp(boolean unconditional)  
  76.         { 
  77.          } 
  78.         public void pauseApp()  
  79.         { 
  80.                 display.setCurrent(null); 
  81.                 props = null; 
  82.          }