📄 multiple_list_midlet.java
字号:
package ch04;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Multiple_List_MIDlet
extends MIDlet {
Display display = Display.getDisplay(this);
//声明一个代表列表框的List对象
List currentList;
/*
1.构造器
*/
public Multiple_List_MIDlet() {
Image aimage = null, bimage = null, cimage = null;
try {
aimage = Image.createImage("/icons/background/star.png");
bimage = Image.createImage("/icons/background/hand.png");
cimage = Image.createImage("/icons/background/boot.png");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
Image[] imageArray = {
aimage, bimage, cimage};
String[] stringArray = {
"选项A", "选项B", "选项C"};
try {
currentList = new List("List界面组件", Choice.MULTIPLE,
stringArray, imageArray);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
display.setCurrent(currentList);
Check c = new Check();
c.start();
}
/*
2.检测类
*/
private class Check
extends Thread {
int temp[] = {
-1, -1, -1};
public final void run() {
boolean flag = false;
while (true) {
int num = currentList.size();
for (int i = 0; i < num; i++) {
if (currentList.isSelected(i)) {
if (temp[i] != i) {
temp[i] = i;
flag = true;
print();
}
}
else {
if (temp[i] == i) {
temp[i] = -1;
flag = true;
print();
}
}
}
try {
sleep(1);
}
catch (Exception e) {
e.getMessage();
}
}
}
/*
3.打印类
*/
void print() {
String s = "";
for (int i = 0; i < temp.length; i++) {
if (temp[i] != -1) {
s = s + "选项 " + (temp[i] + 1) + " 被选中!" + "\n";
}
}
Alert info = new Alert("当前选中项:", s, null, AlertType.INFO);
info.setTimeout(2000);
display.setCurrent(info);
}
}
//启动应用程序
public void startApp() {
}
//挂起应用程序
public void pauseApp() {
}
//撤销应用程序
public void destroyApp(boolean unconditional) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -