midpliftcycle.java

来自「一本介绍手机游戏开发的书中的源代码」· Java 代码 · 共 60 行

JAVA
60
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class midpLiftcycle extends MIDlet implements CommandListener
{
   Display display;
   Form form;
   Command pauseCommand;
   Command exitCommand;
   boolean firstpage;
   boolean over;

   public midpLiftcycle()
   {
      display=Display.getDisplay(this);
      form=new Form("程序生命周期");
      pauseCommand = new Command("暂停", Command.ITEM, 2);
      exitCommand = new Command("离开", Command.EXIT, 1);
      form.append("第一次先运行构造函数初始设定值"); 
      form.addCommand(pauseCommand);
      form.addCommand(exitCommand);
      form.setCommandListener(this); 
   }

   public void startApp()
   {
      if(!firstpage)
        form.append("第二次运行startApp区域程序代码"); 
      else if(over)
        destroyApp(false);
      else
        pauseApp(); 
        
 
      display.setCurrent(form);         
   }

   public void pauseApp()
   {
      form.append("第三次运行pauseApp区域程序代码"); 
   }

   public void destroyApp(boolean unconditional)
   {
      form.append("第四次运行destroyApp离开MIDlet程序");
   }

   public void commandAction(Command cmd, Displayable disp)
   {
      if (cmd == pauseCommand)
      {
         firstpage=true;
         startApp();
      }
      else if (cmd == exitCommand){
         over=true;
         destroyApp(false);
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?