J2ME版本的记事本,类似于西门子C65自带的便签.
//
---------------------------------------------------
//
ContentDataEntity.java
//
---------------------------------------------------
package
src;
import
java.io.
*
;
public
class
ContentDataEntity
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
publicStringtitle;
publicStringdate;
publicStringtext;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicContentDataEntity(Stringtitle,Stringdate,Stringtext)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.title=title;
this.text=text;
this.date=date;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicContentDataEntity()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicbyte[]encode()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
byte[]bytData=null;
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ByteArrayOutputStreambos=newByteArrayOutputStream();
DataOutputStreamdos=newDataOutputStream(bos);
dos.writeUTF(title);
dos.writeUTF(text);
dos.writeUTF(date);
bytData=bos.toByteArray();
dos.close();
bos.close();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
returnbytData;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoiddecode(byte[]data)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ByteArrayInputStreambis=newByteArrayInputStream(data);
DataInputStreamdis=newDataInputStream(bis);
title=dis.readUTF();
text=dis.readUTF();
date=dis.readUTF();
bis.close();
dis.close();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
//
------------------------------------------------------
//
CreatNewTextScreen.java
//
------------------------------------------------------
package
src;
import
javax.microedition.lcdui.
*
;
import
javax.microedition.midlet.
*
;
import
java.util.
*
;
import
javax.microedition.rms.
*
;
public
class
CreatNewTextScreen
extends
Form
implements
CommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateTextFieldtitleField;
privateTextFieldtextField;
privateDateFielddateField;
privateintrecordID;
privatebooleanfirstSave=true;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicCreatNewTextScreen(Displaydisplay,NotePadMIDletMIDlet)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("新建记事");
this.display=display;
this.MIDlet=MIDlet;
titleField=newTextField("标题:","",20,TextField.ANY);
dateField=newDateField("日期",DateField.DATE);
dateField.setDate(newDate());//设定时间为当前时间
textField=newTextField("正文","",140,TextField.ANY);
this.append(titleField);
this.append(dateField);
this.append(textField);
this.addCommand(newCommand("保存",Command.OK,0));
this.addCommand(newCommand("返回",Command.OK,0));
this.setCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayables)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("保存"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
saveData();
}
elseif(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidsaveData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setType(AlertType.INFO);
al.setTimeout(5000);
al.setString("打开数据库出错,请与我联系:norains@163.com");
this.addCommand(newCommand("返回",Command.BACK,0));
display.setCurrent(al);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Calendarcal=Calendar.getInstance();
cal.setTime(dateField.getDate());
StringstrDate=Integer.toString(cal.get(cal.YEAR))+"年"+Integer.toString(cal.get(cal.MONTH))+"月"+Integer.toString(cal.get(cal.DAY_OF_MONTH))+"日";
//StringstrTime=Integer.toString(cal.get(cal.HOUR_OF_DAY))+":"+Integer.toString(cal.get(cal.MILLISECOND))+":"+Integer.toString(cal.get(cal.SECOND));
ContentDataEntitywriteData=newContentDataEntity(titleField.getString(),strDate,textField.getString());
byte[]bytTemp=writeData.encode();
if(firstSave==true)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordID=rs.addRecord(bytTemp,0,bytTemp.length);
firstSave=false;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
rs.setRecord(recordID,bytTemp,0,bytTemp.length);
}
//如果加入数据出错,则会抛出异常,下面这段代码不执行
Alertal=newAlert("");
al.setString("已经成功保存!");
al.setType(AlertType.INFO);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,this);
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("出现错误,无法保存!请与我联系:norains@163.com");
al.setType(AlertType.ERROR);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,this);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//
-----------------------------------------------------
//
EditContentScreen.java
//
-----------------------------------------------------
package
src;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
java.util.Calendar;
import
java.util.Date;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
javax.microedition.lcdui.
*
;
import
javax.microedition.rms.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
class
EditContentScreen
extends
Form
implements
CommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateTextFieldtitleField;
privateTextFieldtextField;
privateDateFielddateField;
privateStringtitle;
privateStringdate;
privateStringtext;
privateintrecordID;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicEditContentScreen(Displaydisplay,NotePadMIDletMIDlet,intID)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("新建记事");
this.display=display;
this.MIDlet=MIDlet;
this.recordID=ID;
readRecordData();
titleField=newTextField("标题",title,20,TextField.ANY);
dateField=newDateField("修改日期",DateField.DATE);
dateField.setDate(newDate());//设定时间为当前时间
textField=newTextField("正文",text,140,TextField.ANY);
this.append(titleField);
this.append(dateField);
this.append(textField);
this.addCommand(newCommand("保存",Command.OK,0));
this.addCommand(newCommand("返回",Command.OK,0));
this.setCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayables)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("保存"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
saveData();
}
elseif(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ViewListScreenviewListScreen=newViewListScreen(display,MIDlet);
display.setCurrent(viewListScreen);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidreadRecordData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSExisted(dbname);
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("打开数据库失败!可能尚未储存数据,请进行游戏后再尝试.如果依然出现错误,请与我联系:norains@163.com");
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ContentDataEntityrecordData=newContentDataEntity();
recordData.decode(rs.getRecord(recordID));
title=recordData.title;
date=recordData.date;
text=recordData.text;
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidsaveData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setType(AlertType.INFO);
al.setTimeout(5000);
al.setString("打开数据库出错,请与我联系:norains@163.com");
this.addCommand(newCommand("返回",Command.BACK,0));
display.setCurrent(al);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Calendarcal=Calendar.getInstance();
cal.setTime(dateField.getDate());
StringstrDate=Integer.toString(cal.get(cal.YEAR))+"年"+Integer.toString(cal.get(cal.MONTH))+"月"+Integer.toString(cal.get(cal.DAY_OF_MONTH))+"日";
//StringstrTime=Integer.toString(cal.get(cal.HOUR_OF_DAY))+":"+Integer.toString(cal.get(cal.MILLISECOND))+":"+Integer.toString(cal.get(cal.SECOND));
ContentDataEntitywriteData=newContentDataEntity(titleField.getString(),strDate,textField.getString());
byte[]bytTemp=writeData.encode();
rs.setRecord(recordID,bytTemp,0,bytTemp.length);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//如果加入数据出错,则会抛出异常,下面这段代码不执行
Alertal=newAlert("");
al.setString("已经成功保存!");
al.setType(AlertType.INFO);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,this);
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("出现错误,无法保存!请与我联系:norains@163.com");
al.setType(AlertType.ERROR);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,this);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//
---------------------------------------
//
EditPasswordScreen.java
//
---------------------------------------
package
src;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
javax.microedition.lcdui.
*
;
import
javax.microedition.rms.RecordEnumeration;
import
javax.microedition.rms.RecordStore;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
class
EditPasswordScreen
extends
Form
implements
CommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privatebooleanpasswordExist=false;
privateDisplaydisplay;
privateStringoldPassword;
privateintrecordID;
privateTextFieldoldPasswordField;
privateTextFieldnewPasswordField1;
privateTextFieldnewPasswordField2;
privateDisplayablenextDisp;
publicEditPasswordScreen(Displaydisplay,DisplayablenextDisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("");
this.display=display;
this.nextDisp=nextDisp;
readPassword();
if(passwordExist==true)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
oldPasswordField=newTextField("请输入原密码:","",20,TextField.PASSWORD);
newPasswordField1=newTextField("请输入新密码:","",20,TextField.PASSWORD);;
newPasswordField2=newTextField("请再次输入新密码:","",20,TextField.PASSWORD);;
this.append(oldPasswordField);
this.append(newPasswordField1);
this.append(newPasswordField2);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
newPasswordField1=newTextField("请输入新密码:","",20,TextField.PASSWORD);;
newPasswordField2=newTextField("请再次输入新密码:","",20,TextField.PASSWORD);;
this.append(newPasswordField1);
this.append(newPasswordField2);
}
this.addCommand(newCommand("提交",Command.OK,0));
this.addCommand(newCommand("返回",Command.OK,0));
this.setCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("提交"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
updataPassword();
}
elseif(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
display.setCurrent(nextDisp);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//读取密码
publicvoidreadPassword()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadSettingDateBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("打开数据库失败!请与我联系:norains@163.com");
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordEnumerationre=rs.enumerateRecords(null,null,false);
if(re.numRecords()!=0)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
passwordExist=true;
recordID=re.nextRecordId();
SettingDataEntitysde=newSettingDataEntity();
sde.decode(rs.getRecord(recordID));
oldPassword=sde.password;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
passwordExist=false;
}
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//更新密码
publicvoidupdataPassword()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadSettingDateBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)//无法打开数据库
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("打开数据库失败!请与我联系:norains@163.com");
}
else//能够打开数据库
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringtmppasd1=newPasswordField1.getString();
Stringtmppasd2=newPasswordField2.getString();
SettingDataEntitysde=newSettingDataEntity(true,newPasswordField1.getString());
byte[]outputData=sde.encode();
if(tmppasd1.equals(tmppasd2))//两次输入的新密码相同
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(passwordExist==true)//原来存在密码
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(oldPassword.equals(oldPasswordField.getString()))//输入的原密码和保存的密码相同
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
rs.setRecord(recordID,outputData,0,outputData.length);
Alertal=newAlert("");
al.setString("成功更改密码!");
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,nextDisp);
}
else//输入的密码和保存的密码不相同
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("原密码不对!");
al.setTimeout(Alert.FOREVER);
al.setType(AlertType.ERROR);
display.setCurrent(al);
}
}
else//原来不存在密码
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordID=rs.addRecord(outputData,0,outputData.length);
Alertal=newAlert("");
al.setString("成功设置密码!");
al.setTimeout(Alert.FOREVER);
display.setCurrent(al,nextDisp);
}
}
else//两次输入的新密码不同
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("两次输入的新密码不相同!");
al.setTimeout(Alert.FOREVER);
al.setType(AlertType.ERROR);
display.setCurrent(al);
}
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
//
--------------------------------------
//
FlashScreen.java
//
--------------------------------------
package
src;
import
javax.microedition.lcdui.game.
*
;
import
javax.microedition.lcdui.
*
;
import
java.util.
*
;
public
class
FlashScreen
extends
GameCanvas
implements
Runnable
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateLayerManagerlayerManager;
privateSpriteanimation;
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
publicFlashScreen(Displaydisplay,NotePadMIDletm)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super(false);
this.display=display;
MIDlet=m;
this.setFullScreenMode(true);
layerManager=newLayerManager();
animation=createAnimation("/res/flash.png");
layerManager.append(animation);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
start();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privateSpritecreateAnimation(Stringpic)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Imageimg=null;
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
img=Image.createImage(pic);
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
returnnewSprite(img,96,54);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
booleanconti=true;
intrate=300;
publicvoidrun()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
longst=0;
longet=0;
Graphicsg=getGraphics();
System.out.println("ret");
while(conti==true)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
st=System.currentTimeMillis();
input();
render(g);
et=System.currentTimeMillis();
if((et-st)<rate)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Thread.sleep(rate-(et-st));
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidinput()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
intkeyState=getKeyStates();
if(keyState!=0)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
stop();
TestPasswordScreenreadSettingScreen=newTestPasswordScreen(display,MIDlet);
//display.setCurrent(readSettingScreen);
//在这里之所以不使用上面这句setCurrent是因为ReadSettingScreen内部构造函数有setCurrent语句;
//如果设定了反而令流程不正常.这应该是个BUG.不明白可以把上面注释划掉测试看看----在NotePadKeyDataBase没建立的时候
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidrender(Graphicsg)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
animation.nextFrame();
layerManager.setViewWindow(0,0,getWidth(),getHeight());
layerManager.paint(g,(getWidth()-96)/2,(getHeight()-54)/2);
flushGraphics();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidstart()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Threadt=newThread(this);
t.start();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidstop()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
conti=false;
}
}
//-----------------------------------------------------
//InfoScreen.java
//-----------------------------------------------------
package
src;
import
javax.microedition.lcdui.
*
;
public
class
InfoScreen
extends
Form
implements
CommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
publicInfoScreen(Displaydisplay,NotePadMIDletMIDlet)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("程序说明");
this.display=display;
this.MIDlet=MIDlet;
this.append("名称:掌上记事版本:0.1 联系:norains@163.com 说明:手机上编写记事的好帮手。兄弟们如果有什么好建议,欢迎和偶联系!");
this.addCommand(newCommand("返回",Command.BACK,0));
this.setCommandListener(this);
}
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
}
}
}
//-----------------------------------------------------
//ListScreen.java
//-----------------------------------------------------
packagesrc;
importjavax.microedition.lcdui.
*
;
public
class
ListScreenextendsListimplementsCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
//传入TestLatencyMIDlet主要是为了能进行退出程序的操作.
publicListScreen(Displaydisplay,NotePadMIDletm)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("",Choice.IMPLICIT);
MIDlet=m;
this.display=display;
Imageimg1,img2,img3,img4,img5;
img1=img2=img3=img4=img5=null;
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
img1=Image.createImage("/res/1.PNG");
img2=Image.createImage("/res/2.PNG");
img3=Image.createImage("/res/3.PNG");
img4=Image.createImage("/res/4.PNG");
img5=Image.createImage("/res/5.PNG");
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
this.append("新建记事",img1);
this.append("浏览条目",img2);
this.append("系统设置",img3);
this.append("程序说明",img4);
this.append("退出程序",img5);
this.setCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayables)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(c==List.SELECT_COMMAND)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Listtmp=(List)s;
intselected=tmp.getSelectedIndex();
Stringlist=tmp.getString(selected);
if(list.equals("新建记事"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
CreatNewTextScreennewTextScreen=newCreatNewTextScreen(display,MIDlet);
display.setCurrent(newTextScreen);
}
elseif(list.equals("浏览条目"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ViewListScreenviewListScreen=newViewListScreen(display,MIDlet);
display.setCurrent(viewListScreen);
}
elseif(list.equals("系统设置"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
SettingScreensettingScreen=newSettingScreen(display,MIDlet);
display.setCurrent(settingScreen);
}
elseif(list.equals("程序说明"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
InfoScreeninfoScreen=newInfoScreen(display,MIDlet);
display.setCurrent(infoScreen);
}
elseif(list.equals("退出程序"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
MIDlet.notifyDestroyed();
}
}
}
}
//-----------------------------------------------------
// NotePadMIDlet.java
//-----------------------------------------------------
package
src;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
javax.microedition.midlet.
*
;
import
javax.microedition.lcdui.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
public
class
NotePadMIDlet
extends
MIDlet
...
{
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privateDisplaydisplay;
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
publicNotePadMIDlet()...{
super();
//TODO自动生成构造函数存根
display=Display.getDisplay(this);
FlashScreenflashScreen=newFlashScreen(display,this);
display.setCurrent(flashScreen);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
protectedvoidstartApp()throwsMIDletStateChangeException...{
//TODO自动生成方法存根
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
protectedvoidpauseApp()...{
//TODO自动生成方法存根
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException...{
//TODO自动生成方法存根
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//-----------------------------------------------------
// RMSUtil .java
//-----------------------------------------------------
package
src;
import
javax.microedition.rms.
*
;
//
数据库操作公共类
public
class
RMSUtil
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
publicstaticRecordStoreopenRSAnyway(Stringrsname)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordStorers=null;
if(rsname.length()>32)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnnull;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
rs=RecordStore.openRecordStore(rsname,true);
returnrs;
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnnull;
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicstaticRecordStoreopenRSExisted(Stringrsname)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordStorers=null;
if(rsname.length()>32)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnnull;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
rs=RecordStore.openRecordStore(rsname,false);
returnrs;
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnnull;
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicstaticbooleandeletRS(Stringrsname)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rsname.length()>32)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnfalse;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordStore.deleteRecordStore(rsname);
returntrue;
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
returnfalse;
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//----------------------------------------
//
SettingDataEntity.H
//----------------------------------------
package
src;
import
java.io.
*
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
class
SettingDataEntity
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
publicbooleanusePassword;
publicStringpassword;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicSettingDataEntity(booleanusePassword,Stringpassword)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.usePassword=usePassword;
this.password=password;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicSettingDataEntity()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicbyte[]encode()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
byte[]bytData=null;
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ByteArrayOutputStreambos=newByteArrayOutputStream();
DataOutputStreamdos=newDataOutputStream(bos);
dos.writeBoolean(usePassword);
dos.writeUTF(password);
bytData=bos.toByteArray();
dos.close();
bos.close();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
returnbytData;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoiddecode(byte[]bytData)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ByteArrayInputStreambis=newByteArrayInputStream(bytData);
DataInputStreamdis=newDataInputStream(bis);
usePassword=dis.readBoolean();
password=dis.readUTF();
dis.close();
bis.close();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//-----------------------------------------------------
//SettingScreen .java
//-----------------------------------------------------
packagesrc;
importjavax.microedition.lcdui.
*
;
importjavax.microedition.rms.
*
;
public
class
SettingScreenextendsFormimplementsCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateDisplayableme=this;//定义此变量是为了在程序中传值
privatebooleansettingDataExist;
privatebooleanrecordUsePassword;
privateChoiceGroupusePasswordCG;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicSettingScreen(Displaydisplay,NotePadMIDletMIDlet)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("设置");
this.display=display;
this.MIDlet=MIDlet;
usePasswordCG=newChoiceGroup("密码保护",ChoiceGroup.EXCLUSIVE);
usePasswordCG.append("是",null);
usePasswordCG.append("否",null);
readSettingData();
if(recordUsePassword==true)//
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
usePasswordCG.setSelectedIndex(0,true);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
usePasswordCG.setSelectedIndex(1,true);
}
this.append(usePasswordCG);
PasswordItemsetPassword=newPasswordItem();
this.append(setPassword);
this.addCommand(newCommand("保存",Command.OK,0));
this.addCommand(newCommand("返回",Command.BACK,0));
this.setCommandListener(this);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("保存"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
saveSettingData();
}
elseif(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenls=newListScreen(display,MIDlet);
display.setCurrent(ls);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidsaveSettingData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
SettingDataEntitysde;
Stringdbname="NotePadSettingDateBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
if(rs==null)//不能打开数据库
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("无法打开数据库!");
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);
}
else//数据库顺利打开
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordEnumerationre=rs.enumerateRecords(null,null,false);
if(re.numRecords()!=0)//记录存在
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
intid;
id=re.nextRecordId();
sde=newSettingDataEntity();
sde.decode(rs.getRecord(id));//取出原来的数据,主要是因为密码在此画面没有,但要写进去
if(usePasswordCG.getSelectedIndex()==0)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
sde.usePassword=true;
}
elseif(usePasswordCG.getSelectedIndex()==1)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
sde.usePassword=false;
}
byte[]writeData=sde.encode();
rs.setRecord(id,writeData,0,writeData.length);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Alertal=newAlert("");
al.setString("设置已保存!");
al.setTimeout(Alert.FOREVER);
ListScreenls=newListScreen(display,MIDlet);
display.setCurrent(al,ls);
}
else//记录不存在
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(usePasswordCG.getSelectedIndex()==0)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
//密码不存在又要密码保护,则直接转到编辑密码画面
EditPasswordScreeneps=newEditPasswordScreen(display,me);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
display.setCurrent(eps);
}
elseif(usePasswordCG.getSelectedIndex()==1)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
sde=newSettingDataEntity();
sde.usePassword=false;
sde.password=null;
byte[]writeData=sde.encode();
rs.addRecord(writeData,0,writeData.length);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Alertal=newAlert("");
al.setString("设置已保存!");
al.setTimeout(Alert.FOREVER);
ListScreenls=newListScreen(display,MIDlet);
display.setCurrent(al,ls);
}
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidreadSettingData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
SettingDataEntitysde;
Stringdbname="NotePadSettingDateBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
if(rs==null)//不能打开数据库
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("无法打开数据库!");
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);
}
else//数据库顺利打开
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
RecordEnumerationre=rs.enumerateRecords(null,null,false);
if(re.numRecords()!=0)//记录存在
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
intid;
id=re.nextRecordId();
sde=newSettingDataEntity();
sde.decode(rs.getRecord(id));
if(sde.usePassword=true)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordUsePassword=true;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordUsePassword=false;
}
}
else//记录不存在
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordUsePassword=false;
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
//定义这个类是为了方便进行按钮操作
publicclassPasswordItemextendsStringItemimplementsItemCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
publicPasswordItem()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("","设置或更改密码",Item.PLAIN);
this.setDefaultCommand(newCommand("更改密码",Command.OK,0));
this.setItemCommandListener(this);
}
publicvoidcommandAction(Commandc,Itemi)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("更改密码"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
//System.out.println("设置!");
EditPasswordScreeneps=newEditPasswordScreen(display,me);
display.setCurrent(eps);
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
//-----------------------------------------------------
//TestPasswordScreen .java
//-----------------------------------------------------
package
src;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
import
javax.microedition.rms.
*
;
import
javax.microedition.lcdui.
*
;
public
class
TestPasswordScreen
extends
Form
implements
CommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateTextFieldpasswordField;
privateinttestNum=0;
privateStringrecordPassword;
privatebooleanusePassword;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicTestPasswordScreen(Displaydisplay,NotePadMIDletMIDlet)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("");
this.display=display;
this.MIDlet=MIDlet;
readSetting();
if(usePassword==true)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
passwordField=newTextField("请在下面方框输入密码:","",20,TextField.PASSWORD);
this.append(passwordField);
this.addCommand(newCommand("确定",Command.OK,0));
this.addCommand(newCommand("退出",Command.OK,0));
this.setCommandListener(this);
display.setCurrent(this);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
//System.out.println("KO");
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("确定"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
testpassword();
}
elseif(cmd.equals("退出"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidreadSetting()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadSettingDateBase";
RecordStorers=RMSUtil.openRSExisted(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
usePassword=false;
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
intid;
SettingDataEntitysettingData=newSettingDataEntity();
RecordEnumerationre=rs.enumerateRecords(null,null,false);
id=re.nextRecordId();
settingData.decode(rs.getRecord(id));
usePassword=settingData.usePassword;
recordPassword=settingData.password;
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidtestpassword()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(recordPassword.equals(passwordField.getString()))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
testNum++;
intnum=3-testNum;
if(testNum<3)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("密码错误");
al.setString("您还有"+num+"次输入机会,超过此次数程序将自动关闭");
al.setTimeout(Alert.FOREVER);
passwordField.setString("");
display.setCurrent(al);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
MIDlet.notifyDestroyed();
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//-----------------------------------------------------
//ViewContentScreen
.java
//-----------------------------------------------------
packagesrc;
importjavax.microedition.lcdui.*;
importjavax.microedition.rms.*;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
publicclassViewContentScreenextendsFormimplementsCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateintrecordID;
privateStringtitle;
privateStringdate;
privateStringtext;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicViewContentScreen(Displaydisplay,NotePadMIDletMIDlet,intrecordID)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("");
this.display=display;
this.MIDlet=MIDlet;
this.recordID=recordID;
readRecordData();
this.append("标题:"+title+" 修改日期:"+date+" 内容:"+text);
this.addCommand(newCommand("返回",Command.BACK,0));
this.addCommand(newCommand("编辑",Command.OK,0));
this.setCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidreadRecordData()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSExisted(dbname);
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("打开数据库失败!可能尚未储存数据,请进行游戏后再尝试.如果依然出现错误,请与我联系:norains@163.com");
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ContentDataEntityrecordData=newContentDataEntity();
recordData.decode(rs.getRecord(recordID));
title=recordData.title;
date=recordData.date;
text=recordData.text;
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ViewListScreenviewListScreen=newViewListScreen(display,MIDlet);
display.setCurrent(viewListScreen);
}
elseif(cmd.equals("编辑"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
EditContentScreeneditContentScreen=newEditContentScreen(display,MIDlet,recordID);
display.setCurrent(editContentScreen);
}
}
}
//-----------------------------------------------------
//ViewListScreen
.java
//-----------------------------------------------------
packagesrc;
importjavax.microedition.lcdui.*;
importjavax.microedition.rms.RecordEnumeration;
importjavax.microedition.rms.RecordStore;
publicclassViewListScreenextendsFormimplementsCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...{
privateDisplaydisplay;
privateNotePadMIDletMIDlet;
privateStringList[]stringList;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicViewListScreen(Displaydisplay,NotePadMIDletMIDlet)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("");
this.display=display;
this.MIDlet=MIDlet;
this.addCommand(newCommand("返回",Command.BACK,0));
this.setCommandListener(this);
creatList();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privatevoidcreatList()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSAnyway(dbname);
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("打开数据库失败!可能尚未储存数据,请进行游戏后再尝试.如果依然出现错误,请与我联系:norains@163.com");
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
intrecordID;
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ContentDataEntityrecordData=newContentDataEntity();
RecordEnumerationre=rs.enumerateRecords(null,null,false);
inti;
stringList=newStringList[re.numRecords()];
if(re.numRecords()!=0)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
for(i=0;i<re.numRecords();i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
recordID=re.nextRecordId();
recordData.decode(rs.getRecord(recordID));
stringList[i]=newStringList(recordData.title,recordID);
this.append(stringList[i]);
//System.out.println(stringList[i].recordID);
}
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
this.append("尚未存储记事!");
}
rs.closeRecordStore();
//RMSUtil.deletRS(dbname);
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Displayabledisp)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
if(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
privateclassStringListextendsStringItemimplementsItemCommandListener
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
publicStringtitle;
publicintrecordID;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicStringList(Stringtitle,intrecordID)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
super("",title,Item.PLAIN);
this.title=title;
this.recordID=recordID;
this.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.setDefaultCommand(newCommand("查看",Command.OK,0));
this.addCommand(newCommand("编辑",Command.OK,1));
this.addCommand(newCommand("删除",Command.OK,2));
this.addCommand(newCommand("取消",Command.OK,3));
//this.addCommand(newCommand("返回",Command.OK,4));在主画面已经有一个"返回",这里可以不要
this.addCommand(newCommand("退出",Command.OK,6));
this.setItemCommandListener(this);
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoiddeleteRecord(intid)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringdbname="NotePadDataBase";
RecordStorers=RMSUtil.openRSExisted(dbname);
try
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
if(rs==null)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Alertal=newAlert("");
al.setString("出现错误,打开数据库!请与我联系:norains@163.com");
al.setType(AlertType.ERROR);
al.setTimeout(Alert.FOREVER);
display.setCurrent(al);
}
else
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
rs.deleteRecord(id);
}
rs.closeRecordStore();
}
catch(Exceptionerro)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
publicvoidcommandAction(Commandc,Itemi)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Stringcmd=c.getLabel();
StringListstringList=(StringList)i;
if(cmd.equals("查看"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ViewContentScreenviewContentScreen=newViewContentScreen(display,MIDlet,stringList.recordID);
display.setCurrent(viewContentScreen);
}
elseif(cmd.equals("编辑"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
EditContentScreeneditContentScreen=newEditContentScreen(display,MIDlet,stringList.recordID);
display.setCurrent(editContentScreen);
}
elseif(cmd.equals("删除"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
deleteRecord(stringList.recordID);
ViewListScreenviewListScreen=newViewListScreen(display,MIDlet);
display.setCurrent(viewListScreen);
}
elseif(cmd.equals("取消"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
//不编写代码可退出选择菜单
}
elseif(cmd.equals("返回"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ListScreenlistScreen=newListScreen(display,MIDlet);
display.setCurrent(listScreen);
}
elseif(cmd.equals("退出"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
MIDlet.notifyDestroyed();
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}