package PingD.notapad;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import seiya.main.calendar.MyCalendar;
/**
* 日记管理软件
* 实现日常的日记记事功能,将心情日记保存在手机中,并提供随时查看功能
* @author PingD
*
*/
public class body extends Canvas implements CommandListener {
//显示对象
Display display;
MyCalendar mainScreen;
private int m = 0;
//主题第一界面
//主界面主题titleMain
//String titleMain = "记事";
//写日记界面主题titleDiary
String titleDiary = "记事";
//查看日记界面主题titleView
String titleView = "查看";
//帮助界面主题titleHelp
String titleHelp = "帮助";
//关于界面主题titleAbout
String titleAbout = "关于";
//第二界面
//增加日记界面主题titleDiaryWrite
String titleDiaryWrite = "记事";
//查看日记列表titleWatchList
String titleWatchList = "查看 ";
//第三界面
//查看日记详细信息界面主题titleViewListMsg
String titleViewListMsg = "详细信息";
//第四界面
//查看界面中的详细信息中的编辑界面主题titleViewListMsgSet
String titleViewListMsgSet = "编辑";
//主界面确定按钮
Command cmdEnterMain;
//返回按钮
Command cmdBack;
//写记事界面
Form frmAddPassword;
//写记事主题框
TextField tfRemark;
//返回按钮
Command cmdBackAdd;
//完成按钮
Command cmdEnterAdd;
//查看记事主界面
List lstView;
//查看详细信息按钮
Command cmdInfo;
//返回按钮
Command cmdBackViewMain;
//查看详细信息窗口
TextBox tbViewInfo;
//编辑按钮
Command cmdModify;
//删除按钮
Command cmdDelView;
//返回按钮
Command cmdBackViewInfo;
//查看详细信息中的编辑信息窗口
Form frmViewModify;
//编辑记事文本内容
TextField tfViewModify;
//返回按钮
Command cmdBackViewModify;
//完成按钮
Command cmdModifyView;
//帮助界面
Form frmHelp;
//帮助界面的返回按钮
Command cmdBackHelp;
//关于界面
Form frmAbout;
//关于界面的返回按钮
Command cmdBackAbout;
//提示窗口,主要用于提示保存成功与否,密码是否正确等
Alert alert;
//记录对象
RecordStore rs;
//存储密码ID内容
String[] id;
//保存显示的密码ID对应的索引号,数组下标为0的代表第一个密码ID,1的代表第二个,依次类推
int[] idIndex;
TextField tfId;
TextField bianji;
/**
*初始化界面元素
*/
public body(MyCalendar mainScreen,Display display) {
// TODO Auto-generated constructor stub
//初始化显示对象
this.display = display;
this.mainScreen =mainScreen;
//初始化主界面确定按钮
cmdEnterMain = new Command("确定", Command.OK, 1);
//添加到主界面
//lstMain.addCommand(cmdEnterMain);
this.addCommand(cmdEnterMain);
//初始化退出按钮
cmdBack = new Command("返回",Command.BACK,1);
//添加到主界面
this.addCommand(cmdBack);
//初始化记事界面
frmAddPassword = new Form(titleDiaryWrite);
tfId = new TextField("标题:","",100,TextField.ANY);
tfRemark = new TextField("记事:", "", 1024, TextField.ANY);
cmdEnterAdd = new Command("完成", Command.OK, 1);
cmdBackAdd = new Command("返回", Command.BACK, 1);
//添加到写日记界面
frmAddPassword.append(tfId);
frmAddPassword.append(tfRemark);
frmAddPassword.addCommand(cmdEnterAdd);
frmAddPassword.addCommand(cmdBackAdd);
//初始化查看日记列表主界面
lstView = new List(titleWatchList,List.IMPLICIT);
cmdInfo = new Command(titleWatchList,Command.SCREEN,1);
cmdBackViewMain = new Command("返回",Command.BACK,1);
//添加到查看日记列表的主界面
lstView.addCommand(cmdInfo);
lstView.addCommand(cmdBackViewMain);
//初始化查看日记详细信息界面
tbViewInfo = new TextBox(titleViewListMsg, "", 1024, TextField.ANY);
cmdDelView =new Command("删除",Command.SCREEN,2);
cmdModify = new Command("编辑",Command.SCREEN,1);
cmdBackViewInfo =new Command("返回",Command.BACK,1);
//添加到查看详细信息界面中
tbViewInfo.addCommand(cmdDelView);
tbViewInfo.addCommand(cmdModify);
tbViewInfo.addCommand(cmdBackViewInfo);
//初始化编辑界面
frmViewModify = new Form(titleViewListMsgSet);
bianji = new TextField("记事:", "", 1024, TextField.ANY);
cmdModifyView = new Command("完成",Command.OK,1);
cmdBackViewModify = new Command("返回",Command.BACK,1);
//添加到编辑界面中去
frmViewModify.addCommand(cmdModifyView);
frmViewModify.append(bianji);
frmViewModify.addCommand(cmdBackViewModify);
//初始化帮助界面
frmHelp = new Form("帮助");
frmHelp.append("记事本软件能帮助你记录日常一些难忘且并不想被更多人知道的事,\"记事\"中可以增加新的记事,\"查看记事\"中可以查看、编辑和删除已有的记事。");
//初始化返回按钮
cmdBackHelp = new Command("返回",Command.BACK,1);
//添加到帮助界面
frmHelp.addCommand(cmdBackHelp);
//初始化关于界面
frmAbout = new Form("关于...");
frmAbout.append("版权所有 2011-世界末日 作者:*-终结者-* 欢迎您提出该版本的更新建议");
//初始化返回按钮
cmdBackAbout = new Command("返回",Command.BACK,1);
//添加到关于界面
frmAbout.addCommand(cmdBackAbout);
//初始化提示窗口
alert = new Alert("心情记事");
//事件处理
this.setCommandListener(this);
frmHelp.setCommandListener(this);
frmAbout.setCommandListener(this);
frmAddPassword.setCommandListener(this);
lstView.setCommandListener(this);
tbViewInfo.setCommandListener(this);
frmViewModify.setCommandListener(this);
}
//主界面的canvas
protected void paint(Graphics g) {
// TODO Auto-generated method stub
//Set bgcolor
g.setColor(0xF0E68C);
g.fillRect(0,0, getWidth(),getHeight());
g.setColor(0x080808);
//第一个框
g.drawRoundRect(40, 35, getWidth()-80, 22, 15, 20);
//第二个框
g.drawRoundRect(40, 85, getWidth()-80, 22, 15, 20);
//第三个框
g.drawRoundRect(40, 135, getWidth()-80, 22, 15, 20);
//第四个框
g.drawRoundRect(40, 185, getWidth()-80, 22, 15, 20);
//设置条框背景
g.setColor(0x2248DD);
g.fillRoundRect(40, ((m*50)+35), getWidth()-80, 22, 15, 20);
//设置字体颜色
g.setColor(0x080808);
g.setFont(Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_LARGE));
g.drawString("记 事", getWidth()/2, 35, Graphics.HCENTER|Graphics.TOP);
g.drawString("查 看 记 事", getWidth()/2, 85, Graphics.HCENTER|Graphics.TOP);
g.drawString("帮 助", getWidth()/2, 135, Graphics.HCENTER|Graphics.TOP);
g.drawString("关 于", getWidth()/2, 185, Graphics.HCENTER|Graphics.TOP);
}
//select the action of mian
protected void keyPressed(int keyCode) {
int keyAction = this.getGameAction(keyCode);
switch (keyAction){
case Canvas.UP:{
m --;
if(m<0) m=3;
break;
}
case Canvas.DOWN:
{
m ++;
if(m>3){
m=0;
}
break;
}
default:
break;
}
repaint();
}
public void commandAction(Command c, Displayable s) {
// TODO Auto-generated method stub
/**
* 事件处理
*/
//处理主界面中返回事件
if (c == cmdBack){
display.setCurrent(mainScreen);
}
//处理主界面中的选择
if (c == cmdEnterMain){
System.out.println(" m ");
//进行各项选择的跳转
switch (m){
//选择“写记事”,显示写记事界面
case 0:
display.setCurrent(frmAddPassword);
break;
case 1:
//选择“查看记事”列表
try{
//获取id记录中的记录条数,如果为空,则提示返回到主界面
RecordStore rs1 = RecordStore.openRecordStore("id", true);
int count = rs1.getNumRecords();
rs1.closeRecordStore();
//如果记录为空,直接返回警告并跳转
if (count == 0){
displayAlert("没有记录!");
//display.setCurrent(lstMain);
display.setCurrent(t
- 1
- 2
前往页