📄 exclusive_list_midlet.java
字号:
package ch04;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Exclusive_List_MIDlet
extends MIDlet {
Display display = Display.getDisplay(this);
//声明一个代表列表框的List对象
List currentList;
/*
1.构造器
*/
public Exclusive_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.EXCLUSIVE,
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 {
public final void run() {
int temp = 0;
Alert info = new Alert("当前选中项:", "选项 1 被选中!", null,
AlertType.INFO);
info.setTimeout(1000);
display.setCurrent(info);
while (true) {
int selected = currentList.getSelectedIndex();
if (temp != selected) {
String s = "选项 " + (selected + 1) + " 被选中!";
info.setString(s);
display.setCurrent(info);
temp = selected;
}
try {
sleep(1);
}
catch (Exception e) {
e.getMessage();
}
}
}
}
//启动应用程序
public void startApp() {
}
//挂起应用程序
public void pauseApp() {
}
//撤销应用程序
public void destroyApp(boolean unconditional) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -