?? listcontrol3.java
字號:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
* 多選列表框的處理
* The MIDlet demonstrates the different types of list supported by MIDP-2.0:
* EXCLUSIVE - a choice having exactly one element selected at time.
* IMPLICIT - a choice in which the currently focused element is
* selected when a Command is initiated.
* MULTIPLE - a choice that can have arbitrary number of elements
* selected at a time.
*
* @version 2.0
*/
public class ListControl3 extends MIDlet implements CommandListener {
private final static Command exitCommand =
new Command("Exit", Command.EXIT, 1);
private final static Command backCommand =
new Command("Back", Command.BACK, 1);
private final static Command okCommand =
new Command("Ok",Command.OK,1);
private Display display;
private List mainList;
private TextBox tb;
public ListControl3() {
display = Display.getDisplay(this);
tb = new TextBox("List Example","List",100,0);
tb.addCommand(exitCommand);
tb.addCommand(backCommand);
tb.setCommandListener(this);
// these are the strings for the choices.
}
protected void startApp() {
// these are the images and strings for the choices.
Image[] imageArray = null;
try {
// load the duke image to place in the image array
Image icon = Image.createImage("/Icon.png");
// these are the images and strings for the choices.
imageArray = new Image[] {
icon,
icon,
icon
};
} catch (java.io.IOException err) {
// ignore the image loading failure the application can recover.
System.out.print("load failed ...");
imageArray = null;
}
String[] stringArray = {
"Textbox A",
"Textbox B",
"Textbox C"
};
mainList = new List("Choose textbox", Choice.MULTIPLE, stringArray,
imageArray);
mainList.addCommand(exitCommand);
mainList.addCommand(okCommand);
mainList.setCommandListener(this);
display.setCurrent(mainList);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
public void commandAction(Command c, Displayable d) {
if (d.equals(mainList)) {
// in the main list
if (c == okCommand) {
if (d.equals(mainList)) {
String[] stringTextbox = {"Selected 1","Selected 2","Selected 3"};
boolean[] selectedArray= new boolean[3];
mainList.getSelectedFlags(selectedArray);
int i = 0;
String str = "";
for (i=0;i<3;i++)
if(selectedArray[i]==true){
str = str + stringTextbox[i] + "\n";
}
tb.setString(str);
display.setCurrent(tb);
}
}
} else {
// in one of the sub-lists
if (c == backCommand) {
display.setCurrent(mainList);
}
}
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -