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

📄 ui_ex9.java

📁 J2ME 无线通信技术应用开发源代码
💻 JAVA
字号:
// 程序名UI_Ex9.java
// 测试多屏幕共用一个Ticker对象
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class UI_Ex9 extends MIDlet implements CommandListener {
  private Display display; // 引用MIDlet的Display 对象
  private Ticker ticker; // 设定一个Ticker对象
  private TextBox textBox1;
  private TextBox textBox2;
  private Command cmdExit; // 设定按钮用于退出MIDlet
  private Command cmdNext; // 设定按钮用于切换屏幕

  // MIDlet构造程序
  public UI_Ex9() {
    display = Display.getDisplay(this);
    ticker = new Ticker("A ticker in tow screen!");
    cmdExit = new Command("Exit", Command.SCREEN, 1);
    cmdNext = new Command("Next", Command.SCREEN, 1);
    textBox1 = new TextBox("Test Ticker","Screen 1\nPress \"Next\" , and go to screen 2!",50,0);
    textBox1.setTicker(ticker);
    textBox1.addCommand(cmdExit);
    textBox1.addCommand(cmdNext);
    textBox1.setCommandListener(this);

    textBox2 = new TextBox("Test Ticker","Screen 2\nPress \"Next\" , and go to screen 1!",50,0);
    textBox2.setTicker(ticker);
    textBox2.addCommand(cmdExit);
    textBox2.addCommand(cmdNext);
    textBox2.setCommandListener(this);
  }

  // 被应用程序管理器调用来启动MIDlet。
  public void startApp() {
    display.setCurrent(textBox1);
  }

  // 一个必要的方法
  public void pauseApp() {
  }

  //一个必要的方法
  public void destroyApp(boolean unconditional) {
  }

  //检查一下是否选择了退出命令
  public void commandAction(Command c, Displayable d) {
    if (c == cmdNext) {
      if (textBox1.isShown()) {
        display.setCurrent(textBox2);
      } else {
        display.setCurrent(textBox1);
      }
    }
    if (c == cmdExit) {
      destroyApp(false);
      notifyDestroyed();
    }
 }
}

⌨️ 快捷键说明

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