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

📄 options.java

📁 J2ME平台上经典的stoSwatch系统。系统架构清晰
💻 JAVA
字号:
package stopwatch;

import javax.microedition.lcdui.*;

public class Options extends List implements CommandListener {

  // Constants for defining our time display format - either display
  // in seconds or display in tenths of seconds.
  public static final int FORMAT_TENTHS  = 0;
  public static final int FORMAT_SECONDS = 1;

  // An array that contains string descriptions of the display formats.
  private static final String[] FORMAT_DESCRIPTIONS = new String[2];
  static {
    FORMAT_DESCRIPTIONS[FORMAT_TENTHS]  = "Tenths of seconds (00:00:1)";
    FORMAT_DESCRIPTIONS[FORMAT_SECONDS] = "Seconds (00:01)";
  };

  private MainMenu parent;                   // Main StopWatch menu screen.
  private int displayFormat = FORMAT_TENTHS; // Initialized to default format.

  /**
   * <p>Construct the displayable</p>
   */
  public Options(MainMenu parent) {
    // Construct a new exclusive List titled "Options" and containing the
    // items in the FORMAT_DESCRIPTIONS array.
    super("Options",            // List title.
          List.EXCLUSIVE,       // List type.  User can only select 1 item.
          FORMAT_DESCRIPTIONS,  // Our defined array of format descriptions.
          null);                // Images.  (we're not including any images).

    // Save the parent so that we can go back to that screen when the user is
    // finished with the Options screen.
    this.parent = parent;

    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

/*
  public Options() {
    super("Options", List.IMPLICIT);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
*/

  private void jbInit() throws Exception {
    // set up this Displayable to listen to command events
    setCommandListener(this);
    // Add commands for OK (when user selects an option) and Cancel.
    addCommand(new Command("OK", Command.OK, 1));
    addCommand(new Command("Cancel", Command.CANCEL, 1));
  }


  /**
   * <p>Handle command events.</p>
   * @param command a Command object identifying the command
   * @param displayable the Displayable on which this event has occurred
   */
  public void commandAction(Command command, Displayable displayable) {
    if (command.getCommandType() == Command.OK) {
      // User pressed ok, so save the user's selection.
      displayFormat = getSelectedIndex();
    }
    else if (command.getCommandType() == Command.CANCEL) {
      // Reset the display to the original selected value.
      setSelectedIndex(displayFormat, true);
    }
    // Now, set the display back to the main menu.
    Display.getDisplay(StopWatch.instance).setCurrent(parent);
  }

  /**
     * <p>Retrieves the selected time display format.</p>
     * @return Either FORMAT_TENTHS or FORMAT_SECONDS
     */
    public int getDisplayFormat() {
      return displayFormat;
    }

    /**
     * <p>Set the selected display format.</p>
     * @param format  display format - either FORMAT_TENTHS or FORMAT_SECONDS
     */
    public void setDisplayFormat(int format) {
      displayFormat = format;          // Save the new display format.
      setSelectedIndex(format, true);  // Set it as the currently selected format.
    }


}

⌨️ 快捷键说明

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