📄 stringitemmidlet.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
// A first MIDlet with simple text and a few commands.
public class StringItemMIDlet extends MIDlet implements CommandListener{
private Command exitCommand;
private Command setLabelCommand;
private Command setTextCommand;
private Command getLabelTextCommand;
private StringItem stringItem1;
private StringItem stringItem2;
private Display display;
public StringItemMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("离开", Command.EXIT, 1);
setLabelCommand = new Command("设置标签",Command.SCREEN,1);
setTextCommand = new Command("设置内容",Command.SCREEN,1);
getLabelTextCommand = new Command("取得",Command.SCREEN,1);
stringItem1 = new StringItem("标签1","内容1");
stringItem2 = new StringItem(null,"内容2");
}
public void startApp() {
Form aForm = new Form("StringItem示范");
aForm.append(stringItem1);
aForm.append(stringItem2);
aForm.addCommand(exitCommand);
aForm.addCommand(setLabelCommand);
aForm.addCommand(setTextCommand);
aForm.addCommand(getLabelTextCommand);
aForm.setCommandListener(this);
display.setCurrent(aForm);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if(c==setLabelCommand)
stringItem1.setLabel("new label");
if(c==setTextCommand)
stringItem2.setText("new text");
if(c==getLabelTextCommand){
Alert alert = new Alert("信息",stringItem1.getLabel() + ":" +
stringItem1.getText(),null,AlertType.INFO);
alert.setTimeout(5000);
display.setCurrent(alert);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -