📄 searchform.java
字号:
package ch12;
import javax.microedition.lcdui.*;
public class SearchForm
extends Form
implements CommandListener {
//声明一个Display对象
private Display display;
//声明一个Displayable对象承载父窗体
private Displayable parent;
//声明一个接收查询关键字的文本域对象
private TextField aTextField;
//声明一个返回上一级窗体按钮Command对象
private Command backCommand;
//声明一个确认按钮Command对象
private Command okCommand;
//声明一个代表记录详细信息的窗体对象
private RecordInfoForm detailInfo;
//声明一个代表搜索类型的变量
private int searchType;
/*
1.构造器
*/
public SearchForm(Display d, Displayable p, String title, int type) {
super("查询记录");
display = d;
parent = p;
searchType = type;
if (searchType == 1) {
aTextField = new TextField("输入姓名", "", 8, TextField.ANY);
}
else {
aTextField = new TextField("输入ID号码", "", 2, TextField.NUMERIC);
}
append(aTextField);
backCommand = new Command("返回", Command.BACK, 1);
okCommand = new Command("确认", Command.OK, 1);
addCommand(backCommand);
addCommand(okCommand);
setCommandListener(this);
}
/*
2.响应按钮事件
*/
public void commandAction(Command c, Displayable s) {
if (c == backCommand) {
display.setCurrent(parent);
}
else {
Record record;
RecordDB rdb = new RecordDB();
if (searchType == 1) {
record = rdb.getRecord(aTextField.getString());
}
else {
record = rdb.getRecord(Integer.parseInt(aTextField.getString()));
}
if (record.getID() < 10) {
detailInfo = new RecordInfoForm(display, parent,
"0" + record.getID() + "|" +
record.getName());
}
else {
detailInfo = new RecordInfoForm(display, parent,
record.getID() + "|" + record.getName());
}
display.setCurrent(detailInfo);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -