📄 itemcommanddemo.java
字号:
//itemCommandDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class itemCommandDemo extends MIDlet implements CommandListener ,ItemCommandListener
{
private Command exitCommand;//定义Command命令对象
private Command pasteCommand, copyCommand, cutCommand;
private Form form;
//定义两个输入框
private String strSave="" ;//保存被Copy,Cut的字符串
private TextField tf1, tf2;//定义输入框
StringItem strTitle;
public itemCommandDemo()
{
exitCommand =new Command("Exit",Command.EXIT,1);
pasteCommand =new Command("Paste",Command.SCREEN,1);
copyCommand =new Command("Copy",Command.SCREEN,1);
cutCommand =new Command("Cut",Command.SCREEN,1);
//创建Form对象
form = new Form("ItemCmd Demo");
//添加文字标签到Form对象中
strTitle = new StringItem("","Copy/Cut/Paste Demo");
form.append(strTitle);
//创建TextField输入框对象并添加到Form对象中
tf1 = new TextField("Text1","",50,TextField.ANY);
form.append(tf1);
tf2 = new TextField("Text2","",50,TextField.ANY);
form.append(tf2);
//将Copy,Cut命令添加到tf1对象中
tf1.addCommand(copyCommand);
tf1.addCommand(cutCommand);
tf1.addCommand(pasteCommand);
tf1.setItemCommandListener(this);
//将Paste命令添加到tf1对象中
tf2.addCommand(copyCommand);
tf2.addCommand(cutCommand);
tf2.addCommand(pasteCommand);
tf2.setItemCommandListener(this);
//添加Form 对象的命令
form.addCommand(exitCommand);
form.setCommandListener(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 item)
{ if (c == copyCommand)
{ //拷贝功能
if(item instanceof TextField)
strSave = ((TextField)item).getString();
} else if (c == cutCommand)
{ //剪切功能
if(item instanceof TextField)
{
strSave = ((TextField)item).getString();
((TextField)item).setString("");
}
} else if (c == pasteCommand)
{ //把剪贴板中内容插入光标位置
if(item instanceof TextField)
((TextField)item).insert(strSave, ((TextField)item).getCaretPosition());
} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -