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

📄 exclusive_list_midlet.java

📁 本光盘是《J2ME无线移动游戏开发》一书的配套光盘
💻 JAVA
字号:
package ch04;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Exclusive_List_MIDlet
    extends MIDlet {

  Display display = Display.getDisplay(this);

  //声明一个代表列表框的List对象
  List currentList;

  /*
   1.构造器
   */
  public Exclusive_List_MIDlet() {
    Image aimage = null, bimage = null, cimage = null;
    try {
      aimage = Image.createImage("/icons/background/star.png");
      bimage = Image.createImage("/icons/background/hand.png");
      cimage = Image.createImage("/icons/background/boot.png");
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }

    Image[] imageArray = {
        aimage, bimage, cimage};

    String[] stringArray = {
        "选项A", "选项B", "选项C"};

    try {
      currentList = new List("List界面组件", Choice.EXCLUSIVE,
                             stringArray, imageArray);
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }

    display.setCurrent(currentList);

    Check c = new Check();
    c.start();
  }

  /*
   2.检测类
   */
  private class Check
      extends Thread {
    public final void run() {
      int temp = 0;
      Alert info = new Alert("当前选中项:", "选项 1 被选中!", null,
                             AlertType.INFO);
      info.setTimeout(1000);
      display.setCurrent(info);

      while (true) {
        int selected = currentList.getSelectedIndex();
        if (temp != selected) {
          String s = "选项 " + (selected + 1) + " 被选中!";
          info.setString(s);

          display.setCurrent(info);

          temp = selected;
        }
        try {
          sleep(1);
        }
        catch (Exception e) {
          e.getMessage();
        }
      }
    }
  }

  //启动应用程序
  public void startApp() {
  }

  //挂起应用程序
  public void pauseApp() {
  }

  //撤销应用程序
  public void destroyApp(boolean unconditional) {
  }

}

⌨️ 快捷键说明

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