📄 test.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDletStateChangeException;
public class test extends MIDlet implements CommandListener,ItemStateListener{
private Form form;
private TextBox tb;
private Alert alert;
private List list;
Display display;
Command ShowTextBox;
Command ShowList;
Command ShowAlert;
Command SelectOnList;
Command DeleteOneItemOfList;
Command AddOneItemList;
Command GoBack;
String[] ListContext={"list1","list2","list3"};
public test() {
// TODO Auto-generated constructor stub
form=new Form("FORM窗体展示:");
form.append("本例子展示LIST,TEXTBOX,ALERT的用法,请单击\"菜单\"查看");
tb=new TextBox("TextBox","textbox的内容",50,TextField.ANY);
display=Display.getDisplay(this);
ShowTextBox=new Command("显示textbox",Command.OK,1);
ShowList=new Command("显示List",Command.OK,1);
ShowAlert=new Command("显示Alert",Command.OK,1);
SelectOnList=new Command("选择List",Command.OK,2);
DeleteOneItemOfList=new Command("删除List",Command.OK,2);
AddOneItemList=new Command("添加一条List",Command.OK,2);
GoBack=new Command("返回",Command.OK,1);
alert=new Alert("ALERT实例","alert 内容",null,AlertType.INFO);
list=new List("LIST实例",List.EXCLUSIVE,ListContext,null);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
display=Display.getDisplay(this);
display.setCurrent(form);
tb.addCommand(GoBack);
tb.setCommandListener(this);
form.addCommand(ShowAlert);
form.addCommand(ShowList);
form.addCommand(ShowTextBox);
list.addCommand(SelectOnList);
list.addCommand(DeleteOneItemOfList);
list.addCommand(AddOneItemList);
list.addCommand(GoBack);
form.setCommandListener(this);
form.setItemStateListener(this);
list.setCommandListener(this);
}
public void commandAction(Command c,Displayable d){
if(c==ShowTextBox){
display.setCurrent(tb);
tb.setString("textbox setstring");
}else if(c==ShowList){
display.setCurrent(list);
}else if(c==ShowAlert){
display.setCurrent(alert);
alert.setTimeout(Alert.FOREVER);
AlertType.INFO.playSound(display);
display.flashBacklight(1500);
}else if(c==SelectOnList){
list.setTitle("您选择的是:"+list.getString(list.getSelectedIndex()));
}else if(c==DeleteOneItemOfList){
try{
int Index=list.getSelectedIndex();
list.delete(Index);
}catch(IndexOutOfBoundsException e){
System.out.println(e.toString());
}
}else if(c==AddOneItemList){
list.append("新条目", null);
}else if(c==GoBack){
display.setCurrent(form);
}
}
public void itemStateChanged(Item item){
if(item.getLabel().equals("list1")){
list.setSelectedIndex(1,true);
if(list.isSelected(1)){
list.setSelectedIndex(0, true);
list.setSelectedIndex(2, true);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -