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

📄 gauge_midlet.java

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

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

public class Gauge_MIDlet
    extends MIDlet {

  /*
      1.构造器
   */
  public Gauge_MIDlet() {

    Form frm = new Form("Gauge界面组件");
    Display display = Display.getDisplay(this);
    display.setCurrent(frm);

    frm.append("第一个进度条可响应用户.");
    frm.append(new Gauge("交互进度条", true, 30, 0));
    frm.append("第二个进度条不响应用户.");
    frm.append(new NoneInteractiveGauge());

  }

  /*
      2.非交互进度条
   */
  class NoneInteractiveGauge
      extends Gauge
      implements Runnable {

    //每次变换的幅度
    private int movement = 1;

    //启动线程
    public NoneInteractiveGauge() {
      super("非交互进度条", false, 30, 0);
      new Thread(this).start();
    }

    //此方法实现进度条从左至右变化
    public void run() {
      while (true) {
        //当前值加1
        int newValue = getValue() + movement;
        //超过最大值从新开始
        if (newValue >= 30) {
          movement = -1;
        }
        else {
          if (newValue <= 0) {
            movement = 1;
          }
        }
        //设置当前值
        setValue(newValue);
        try {
          Thread.currentThread().sleep(1000);
        }
        catch (InterruptedException err) {
          System.out.println(err.getMessage());
        }
      }
    }
  }

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

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

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

}

⌨️ 快捷键说明

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