searchform.java
来自「本光盘是《J2ME无线移动游戏开发》一书的配套光盘」· Java 代码 · 共 82 行
JAVA
82 行
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 + =
减小字号Ctrl + -
显示快捷键?