📄 mainmenu.java
字号:
package stopwatch;
import javax.microedition.lcdui.*;
public class MainMenu extends List implements CommandListener {
// These are our menu choices that will be in our List.
private static final String[] MENU_CHOICES = new String[2];
static {
MENU_CHOICES[0] = "Run StopWatch";
MENU_CHOICES[1] = "Options";
};
// StopWatch screen. (the screen that displays the actual stopwatch time).
private StopWatchDisplay stopWatchDisplay = new StopWatchDisplay(this);
// Options screen to allow user to set preferences.
private Options optionsScreen = new Options(this);
public MainMenu() {
//super("StopWatch Menu", List.IMPLICIT);
// Create a new List containing our defined menu choices. We will title
// our list "StopWatch Menu".
super("StopWatch Menu", // List title.
List.IMPLICIT, // List type.
MENU_CHOICES, // Our defined array of menu choices.
null); // Images. (we're not including any images).
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 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) {
// First, get the type of command that was just received.
int commandType = command.getCommandType();
// Now perform an action based on the type of command received.
if (commandType == Command.EXIT) {
// We just received the EXIT command (user just pressed EXIT), so quit
// the MIDlet.
StopWatch.quitApp();
}
else {
// User must have selected one of the menu items. Find out what is
// selected and display the appropriate screen.
String selectedItem = getString(getSelectedIndex());
if (selectedItem.equals(MENU_CHOICES[0])) {
// Show the StopWatch screen.
Display.getDisplay(StopWatch.instance).setCurrent(stopWatchDisplay);
} else if (selectedItem.equals(MENU_CHOICES[1])) {
// Show the Options screen.
Display.getDisplay(StopWatch.instance).setCurrent(optionsScreen);
}
}
}
/**
* <p>Retrieves the selected display format from the options screen.</p>
* @return time display format
*/
public int getDisplayFormat() {
return optionsScreen.getDisplayFormat();
}
/**
* <p>Sets the selected display format in the options screen.</p>
* @param format time display format
*/
public void setDisplayFormat(int format) {
optionsScreen.setDisplayFormat(format);
}
/**
* <p>Releases references. Used when quitting the MIDlet to make sure that
* all variable references are null.</p>
*/
void destroy() {
optionsScreen = null;
stopWatchDisplay.destroy();
stopWatchDisplay = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -