📄 addressbookmidlet.java~101~
字号:
void editScreen(){
ui_form=new Form("修改");
wordedit=new TextField("单词","",50,TextField.ANY);
ui_form.append(wordedit);
meanedit=new TextField("新意思","",50,0);
ui_form.append(meanedit);
ui_form.addCommand(edit);
ui_form.addCommand(mainmenu);
ui_form.addCommand(quit);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}
//删除词汇表界面
void deleteScreen(){
ui_form=new Form("删除");
word=new TextField("单词","",50,0);
ui_form.append(word);
ui_form.addCommand(delete);
ui_form.addCommand(mainmenu);
ui_form.addCommand(quit);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}
//浏览词汇表界面
void seeScreen(){
address_see();
}
//根据浏览词汇表的首字母界面
void address_see(){
items=new List("首字母列表",List.IMPLICIT);
try {
for(int i=0;i<26;i++){
char c='a';
c+=i;
items.append(String.valueOf(c),null);
}
} catch (Exception e) {
}
display.setCurrent(items);
items.addCommand(show);
items.addCommand(mainmenu);
items.setCommandListener(this);
}
//显示字母表记录
void inword_show(String init_item){
String temp="";
String mean_str;
String word_str;
String item;
try{
RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
ui_form = new Form("详细信息");
while (re.hasNextElement()) {
String name1 = new String(re.nextRecord());
item = name1.substring(name1.indexOf("?")+1);
if (item.equals(init_item)) {
word_str = name1.substring(0, name1.indexOf("#"));
mean_str = name1.substring(name1.indexOf("#") + 1,name1.indexOf("?"));
temp = temp +" 单词:" + word_str + " 中文意思:" + mean_str +"\n";
}
}
}catch(Exception e){
word_str ="";
}
ui_form.append(temp);
ui_form.addCommand(quit);
ui_form.addCommand(opermenu);
ui_form.addCommand(showback);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}
//添加记录
void rec_add(String wordstr,String meanstr){
char[] a=wordstr.toCharArray();
String init=String.valueOf(a[0]);
String data=wordstr+"#"+meanstr+"?"+init;
System.out.print(data);
try{
byte[] b=data.getBytes();
recordStore.addRecord(b,0,b.length);
ui_form=new Form("添加成功");
ui_form.append("成功添加一条记录");
ui_form.addCommand(quit);
ui_form.addCommand(opermenu);
ui_form.addCommand(addnowback);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}catch(RecordStoreException rse){
rse.printStackTrace();
}
}
//查询记录
void rec_search(String wordstr){
String temp="";
String mean_str;
String word_str;
String check_word;
int size=wordstr.length();
try{
RecordEnumeration re=recordStore.enumerateRecords(null,null,false);
ui_form=new Form("查询结果");
while(re.hasNextElement()){
String str=new String(re.nextRecord());
try{
word_str=str.substring(0,str.indexOf("#"));
}catch(Exception ef){
word_str="请检查单词是否拼写正确!";
ef.printStackTrace();
}
if(word_str.length()>=size){
check_word=word_str.substring(0,size);
if(check_word.equals(wordstr)){
try{
mean_str=str.substring(str.indexOf("#")+1,str.indexOf("?"));
}catch(Exception e){
mean_str="";
}
temp=mean_str;
}
}
}
if(temp.equals("")){
temp="没有找到此记录......";
}
ui_form.append(temp);
ui_form.addCommand(quit);
ui_form.addCommand(opermenu);
ui_form.addCommand(searchback);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}catch(RecordStoreNotOpenException rsnoe){
rsnoe.printStackTrace();
}catch(InvalidRecordIDException irid){
irid.printStackTrace();
}catch(RecordStoreException rse){
rse.printStackTrace();
}
}
//修改词汇记录
void rec_edit(String wordstr,String meanstr){
int id=1;
int edit_id=0;
String word_str;
String temp="error";
try{
RecordEnumeration re=recordStore.enumerateRecords(null,null,false);
ui_form=new Form("修改");
while(re.hasNextElement()){
id=re.nextRecordId();
String word1=new String(recordStore.getRecord(id));
try{
word_str=word1.substring(0,word1.indexOf("#"));
}catch(Exception ef){
word_str="请检查单词拼写是否正确";
}
if(word_str.equals(wordstr)){
edit_id=id;
}
}
if(edit_id!=0){
String data=wordstr+"#"+meanstr;
byte[] b_data=data.getBytes();
recordStore.setRecord(edit_id,b_data,0,b_data.length);
temp="成功修改一条记录";
}else{
temp="要修改的记录不在词汇表内!";
}
}catch(Exception e){
e.printStackTrace();
}
ui_form.append(temp);
ui_form.addCommand(quit);
ui_form.addCommand(opermenu);
ui_form.addCommand(editback);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}
//删除词汇记录
void rec_delete(String wordstr){
String temp="";
String word_str;
int id;
int del_id=0;
try{
RecordEnumeration re=recordStore.enumerateRecords(null,null,false);
ui_form=new Form("删除结果");
while(re.hasNextElement()){
id=re.nextRecordId();
String word1=new String(recordStore.getRecord(id));
try{
word_str=word1.substring(0,word1.indexOf("#"));
}catch(Exception ef){
word_str="请检查单词拼写是否正确!";
}
if(word_str.equals(wordstr)){
del_id=id;
}
}
if(del_id!=0){
recordStore.deleteRecord(del_id);
temp="成功删除该单词!";
}else{
temp="所指定的记录不在词汇表内!";
}
}catch(Exception e){
}
ui_form.append(temp);
ui_form.addCommand(quit);
ui_form.addCommand(opermenu);
ui_form.addCommand(deleteback);
ui_form.setCommandListener(this);
display.setCurrent(ui_form);
}
//关闭记录存储
public void close()throws RecordStoreNotOpenException,RecordStoreException{
recordStore.closeRecordStore();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -