📄 customitemdemo.java
字号:
//customItemDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import itemex.*;
public class customItemDemo extends MIDlet implements CommandListener ,ItemCommandListener
{
private Command exitCommand,editCommand,okCommand;
private Form form;
TableItem table1;
TextField tfEdit;
public customItemDemo()
{
exitCommand =new Command("Exit",Command.EXIT,1);
form = new Form("CustomeItemDemo");
form.addCommand(exitCommand);
form.setCommandListener(this);
table1 = new TableItem("4*3 table", 4, 3, 40, 20);
form.append("----Head----");
form.get(0).setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
form.append(table1);
form.append("----Tail----");
form.get(2).setLayout(Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_2);
//设置单元格文字
table1.setText("J2EE",0,0);
table1.setText("J2SE",0,1);
table1.setText("J2ME",0,2);
//为TableItem 对象添加命令,并设置默认命令
editCommand =new Command("Edit",Command.SCREEN,1);
table1.addCommand(editCommand);
table1.setItemCommandListener(this);
table1.setDefaultCommand(editCommand);
//为TextField 对象添加命令,并设置默认命令
okCommand =new Command("OK",Command.SCREEN,1);
tfEdit = new TextField("TextEdit","",10, TextField.ANY );
form.append(tfEdit);
tfEdit.addCommand(okCommand);
tfEdit.setItemCommandListener(this);
}
protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean p1 )
{
}
public void commandAction(Command c,Displayable d)
{
if (c ==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
public void commandAction(Command c, Item i)
{
if (c == editCommand)
{
System.out.println("editCommand from TableItem");
tfEdit.setString(table1.getText( table1.getCurrentX(),table1.getCurrentY()));
Display.getDisplay(this).setCurrentItem(tfEdit);
}
if (c == okCommand)
{
System.out.println("okCommand from TextField");
table1.setText(tfEdit.getString(),table1.getCurrentX(),table1.getCurrentY());
Display.getDisplay(this).setCurrentItem(table1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -