?? listtest.java
字號:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ListTest extends MIDlet implements CommandListener{
private List menu;
private List implicit_list;
private List exclusive_list;
private List multiple_list;
private Command okCommand = new Command("OK", Command.OK, 1);
private Command backCommand = new Command("Back", Command.BACK, 1);
private String[] options={"Option A","Option B","Option C"};
private Display display;
public ListTest() {
//create an implicit choice list, and use it as start menu
menu= new List("Choose demo", List.IMPLICIT);
menu.append("Implicit choice list",null);
menu.append("Multiple choice list",null);
menu.insert(1, "Exclusive choice list",null);
menu.append("Exit",null);
menu.setCommandListener(this);
//create an implicit list
implicit_list= new List("Implicit-choice list",List.IMPLICIT,
options, null);
/**
* Add an empty command to present commands in the same
* layout as the rest.
*/
//implicit_list.addCommand(okCommand);
implicit_list.addCommand(backCommand);
implicit_list.setCommandListener(this);
//create an exclusive list
exclusive_list= new List("Exclusive-choice list",List.EXCLUSIVE,
options, null);
exclusive_list.addCommand(okCommand);
exclusive_list.addCommand(backCommand);
exclusive_list.setCommandListener(this);
//create a mutiple choice list
multiple_list= new List("Multiple-choice list",List.MULTIPLE,
options, null);
multiple_list.addCommand(okCommand);
multiple_list.addCommand(backCommand);
multiple_list.setCommandListener(this);
display=Display.getDisplay(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(menu);
}
/**
* Pause the MIDlet
*/
public void pauseApp() {
}
/**
* Called by the framework before the application is unloaded
*/
public void destroyApp(boolean unconditional) {
//clear everything
menu=null;
implicit_list=null;
exclusive_list=null;
multiple_list=null;
okCommand = null;
backCommand = null;
display=null;
}
public void commandAction(Command c, Displayable d) {
if(d==menu && c==List.SELECT_COMMAND) {
switch(menu.getSelectedIndex()) {
case 0: //implicit choice list
display.setCurrent(implicit_list);
break;
case 1: //exclusive choice list
display.setCurrent(exclusive_list);
break;
case 2: //multiple choice list
display.setCurrent(multiple_list);
break;
case 3: //exit
destroyApp(true);
notifyDestroyed();
break;
default:
}
}
else if(d==implicit_list && c==List.SELECT_COMMAND) {
System.out.println(options[((List)d).getSelectedIndex()]+" is selected");
}
else if(d==exclusive_list && c==okCommand) {
System.out.println(options[((List)d).getSelectedIndex()]+" is selected");
}
else if(d==multiple_list && c==okCommand) {
//report which options are selected
boolean[] selected= new boolean[options.length];
((List)d).getSelectedFlags(selected);
for(int i=0; i<options.length; i++) {
if(selected[i]) {
System.out.println(options[i]+" is selected");
}
}
}
else if(c==backCommand) {
display.setCurrent(menu);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -