⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaydemo.java~9~

📁 J2ME高级用户界面的学习代码
💻 JAVA~9~
字号:
//DisplayDemo.javaimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class DisplayDemo extends MIDlet implements CommandListener{  private Display display;  private TextBox scrHelp;  private TextBox scrJump;  private TextBox[] myScreen;  private Command cmdBack = new Command("Back",Command.BACK,1);  private Command cmdForw = new Command("Forward",Command.SCREEN,1);  private Command cmdJump = new Command("Goto",Command.SCREEN,2);  private Command cmdExit = new Command("Exit",Command.SCREEN,2);  private Command cmdHelp = new Command("Help",Command.HELP,1);  private Command cmdCanc = new Command("Cancel",Command.CANCEL,1);  private Command cmdConf = new Command("OK",Command.OK,1);  static int MaxHistory = 8;  static int MaxScreen = 4;  int[] history;  int currentPos;  int historyLen;  public DisplayDemo()  {    display = Display.getDisplay(this);    String helpStr = new String("This is a Demo of Multi-Screens");    scrHelp = new TextBox("Help",helpStr,100,0);    scrHelp.addCommand(cmdCanc);    scrHelp.setCommandListener(this);    scrJump = new TextBox("Goto"," ",2,2);    scrJump.addCommand(cmdConf);    scrJump.addCommand(cmdCanc);    scrJump.setCommandListener(this);    myScreen = new TextBox[MaxScreen];    myScreen[0] = createScreen("Screen 1","This is Screen 1");    myScreen[1] = createScreen("Screen 2","This is Screen 2");    myScreen[2] = createScreen("Screen 3","This is Screen 3");    myScreen[3] = createScreen("Screen 4","This is Screen 4");    history = new int[MaxHistory];    currentPos = -1;    historyLen = 0;  }  public void startApp()  {    gotoScreen(0);    addHistory(0);  }  public void pauseApp(){}  public void destroyApp(boolean unconditional){}  private TextBox createScreen(String screenTitle,String screenContent)  {    TextBox tempScreen = new TextBox(screenTitle,screenContent,50,0);    tempScreen.addCommand(cmdForw);    tempScreen.addCommand(cmdBack);    tempScreen.addCommand(cmdJump);    tempScreen.addCommand(cmdHelp);    tempScreen.addCommand(cmdExit);    tempScreen.setCommandListener(this);    return tempScreen;  }  private void addHistory(int num)  {    if(historyLen < MaxHistory)    {      historyLen++;      history[historyLen] = num;      currentPos++;    }    else    {      for(int i = 0;i < MaxHistory;i++)      {        history[i] = history[i + 1];      }      history[MaxHistory] = num;      currentPos = historyLen - 1;    }  }  void gotoScreen(int num)  {    display.setCurrent(myScreen[num]);  }  public void commandAction(Command c,Displayable d)  {    if(cmdBack == c)    {      if(currentPos > 0)      {        currentPos--;        gotoScreen(history[currentPos]);      }      return;    }    if(cmdForw == c)    {      if(currentPos < historyLen)      {          currentPos++;          gotoScreen(history[currentPos]);      }      return;    }    if(cmdJump ==  c)    {      display.setCurrent(scrJump);      return;    }    if(cmdCanc == c)    {      gotoScreen(history[currentPos]);      return;    }    if(cmdConf == c)    {      int next = Integer.parseInt(scrJump.getString());      if((next > 0)&&(next <= MaxScreen))      {        display.setCurrent(myScreen[next - 1]);        addHistory(next - 1);      }      return;    }    if(cmdExit == c)    {      destroyApp(false);      notifyDestroyed();    }  }}

⌨️ 快捷键说明

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