📄 messagemidlet.java.txt
字号:
/** Constructor */
public MenuMIDLet() {
super('通讯录',List.IMPLICIT);
for(int i=0;i<PUBCLASS.MENULIST.LENGTH;I++){ class=kwd this.append(pubclass.Get_MenuList(i),pubclass.createImage('/images/tel.png'));
}
//构造按钮
pubclass.selectCommand = new Command('选择', Command.SCREEN, 2);
pubclass.exitCommand = new Command('离开', Command.EXIT, 1);
//添加监听
this.addCommand(pubclass.exitCommand);
this.addCommand(pubclass.selectCommand);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c == pubclass.selectCommand ){
int selectitem = this.getSelectedIndex();
//尽量不使用Switch,用If提高速度,虽然麻烦点,经验所得
if (selectitem == 0) {
pubclass.Return_MainMIDLet();
}
if (selectitem == 1) {
pubclass.Return_AboutMIDlet();
}
}
//退出
if(c == pubclass.exitCommand){
MessageMIDlet.quitApp();
}
}
}
//=========================end================================
//=========================AboutMIDlet关于作者类(显示作者信息)================================
package messagemidlet;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
public class AboutMIDlet extends Form implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public AboutMIDlet() {
super('');
this.setTitle('关于作者');
StringItem stringitem = new StringItem('作者介绍','01网通(2)02号. 姓名:Sukey. 版权所有:Sukey.');
this.append(stringitem);
//构造按钮
pubclass.menuCommand = new Command('主目录', Command.SCREEN, 1);
pubclass.exitCommand = new Command('离开', Command.BACK, 1);
//添加监听
this.addCommand(pubclass.menuCommand);
this.addCommand(pubclass.exitCommand);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c ==pubclass.menuCommand ){
pubclass.Return_MenuMIDLet();
}
if(c == pubclass.exitCommand){
MessageMIDlet.quitApp();
}
}
}
//=========================end================================
//=========================MainMIDLet通讯录里表类================================
package messagemidlet;
//
import javax.microedition.lcdui.*;
public class MainMIDLet extends List implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public MainMIDLet() {
super('通讯录',List.IMPLICIT);
//显示列表
for(int i=0;i<PUBCLASS.MAINLIST.LENGTH;I++){ class=kwd this.append(pubclass.Get_MainList(i),pubclass.createImage('/images/tel.png'));
}
//构造按钮
pubclass.selectCommand = new Command('选择', Command.OK, 1);
pubclass.menuCommand = new Command('主目录', Command.EXIT, 2);
//添加监听
this.addCommand(pubclass.selectCommand);
this.addCommand(pubclass.menuCommand);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == pubclass.selectCommand) {
int selectitem = this.getSelectedIndex();
//尽量不使用Switch,用If提高速度,虽然麻烦点,经验所得
if (selectitem == 0) {
pubclass.Return_PersonListMIDLet();
}
if (selectitem == 1) {
pubclass.Return_SearchMIDlet();
}
if (selectitem == 2) {
pubclass.Return_AddPersonMIDLet();
}
if (selectitem == 3) {
}
}
if(c == pubclass.menuCommand){
pubclass.Return_MenuMIDLet();
}
}
}
//=========================end================================
//=========================AddPersonMIDLet添加联系人类================================
package messagemidlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class AddPersonMIDLet extends Form implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public AddPersonMIDLet() {
super('');
this.setTitle('添加联系人');
for(int i=0;i<PUBCLASS.PERSON.LENGTH;I++){ class=kwd this.append(pubclass.person[i]);
}
//构造按钮
pubclass.exitCommand = new Command('返回', Command.OK, 1);
pubclass.okCommand = new Command('保存', Command.BACK, 2);
//添加监听
this.addCommand(pubclass.exitCommand);
this.addCommand(pubclass.okCommand);
this.setCommandListener(this);
}
//添加记录
private void AddRecord(){
RecordStore rs =null;
rs = pubclass.Open();
try {
//取得textfield每个直,以数组形式保存
String[] getstring = new String[pubclass.Length];
for(int i=0;i<PUBCLASS.LENGTH;I++){ class=cmt //构造personclass实例
PersonClass personclass = new PersonClass();
personclass.Write(getstring);
byte[] data = personclass.changeToByteArray();
int recordId = personclass.GetRecordID();
if (recordId != -1) {
rs.setRecord(recordId, data, 0, data.length);
}
else {
//添加记录
recordId = rs.addRecord(data, 0, data.length);
}
SetGet.SetDelId(0);
MainMIDLet mainmidlet = new MainMIDLet();
pubclass.Alert('添加成功!返回中.......', mainmidlet);
}
catch (Exception e) {
pubclass.Alert('添加联系人失败');
}
}
public void commandAction(Command c, Displayable d) {
if(c == pubclass.okCommand){
//判断至少要填写姓名
if(pubclass.person[0].getString() == null || pubclass.person[0].getString() == '' ){
pubclass.Alert('至少要填写姓名');
}else{
//添加记录
AddRecord();
}
}
if(c == pubclass.exitCommand){
pubclass.Return_MainMIDLet();
}
}
}
//=========================end================================
//=========================PersonListMIDlet联系人列表类(显示联系人列表)================================
package messagemidlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class PersonListMIDlet extends List implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
private PersonClass personclass = new PersonClass();
public int[] recordIDs;
/** Constructor */
public PersonListMIDlet() {
super('联系人列表',List.IMPLICIT);
PersonList();
//构造按钮
pubclass.selectCommand = new Command('查看', Command.SCREEN, 2);
pubclass.exitCommand = new Command('编辑', Command.EXIT, 1);
//添加监听
this.addCommand(pubclass.exitCommand);
this.addCommand(pubclass.selectCommand);
this.setCommandListener(this);
}
//用户列表
public void PersonList() {
RecordStore rs = null;
rs = pubclass.Open();
try {
byte[] data;
//建立枚举,取出记录
RecordEnumeration re = rs.enumerateRecords(null, null, false);
//判断是否又记录
if (re.hasNextElement()) {
int records=re.numRecords();//取得记录数
recordIDs=new int[records];//recordID记录数组
for(int i=0;i<RECORDS;I++){ class=cmt recordIDs[i]="re.nextRecordId();//保存id
data = rs.getRecord(recordIDs[i]);
personclass.changeFromByteArray(data);
this.append(''+personclass.getPerson(0)+'',pubclass.createImage('/images/per.png'));//插入此record名称
}
SetGet.SetIsTrue(true);
}
else {
this.append('还未添加联系人?', null);
SetGet.SetIsTrue(false);
}
}
catch (Exception e) {
}
}
//全局变量ID
private void SetGetId() {
int itemid = this.getSelectedIndex();
SetGet.SetId(recordIDs[itemid]);
}
//全局变量DelID
private void SetGetDelId() {
int itemid = this.getSelectedIndex();
SetGet.SetDelId(recordIDs[itemid]);
}
private void SetGetModId(){
int itemid = this.getSelectedIndex();
SetGet.SetModId(recordIDs[itemid]);
}
//提示信息并返回
public void AlerNone(){
MainMIDLet mainmidlet = new MainMIDLet();
pubclass.Alert('无法操作',mainmidlet);
}
public void commandAction(Command c, Displayable d) {
if(c ==pubclass.exitCommand ){
if (SetGet.GetIsTrue()){
this.SetGetDelId();
this.SetGetModId();
pubclass.Return_OperateMIDLet();
}else{
AlerNone();
}
}
if(c ==pubclass.selectCommand ){
if (SetGet.GetIsTrue()){
this.SetGetId();
pubclass.Return_PersonDetailMIDlet();
}else{
AlerNone();
}
}
}
}
//=========================end================================
//=========================SearchMIDlet查找类================================
package messagemidlet;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
public class SearchMIDlet extends TextBox implements CommandListener{
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public SearchMIDlet() {
super('查找联系人','',256,0);
//构造按钮
pubclass.menuCommand = new Command('查找', Command.SCREEN, 1);
pubclass.okCommand = new Command('主目录', Command.BACK, 1);
//添加监听
this.addCommand(pubclass.menuCommand);
this.addCommand(pubclass.okCommand);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c ==pubclass.okCommand ){
pubclass.Return_MenuMIDLet();
}
if(c ==pubclass.menuCommand){
//设置全局变量
SetGet.SetStr(this.getString());
pubclass.Return_SearchOutMIDlet();
}
}
}
//=========================end================================
//=========================SearchOutMIDlet查找结果类================================
package messagemidlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;
public class SearchOutMIDlet extends List implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
private PersonClass personclass = new PersonClass();
public int[] recordIDs;
/** Constructor */
public SearchOutMIDlet() {
super('查找结果', List.IMPLICIT);
PersonList();
//构造按钮
pubclass.selectCommand = new Command('查看', Command.SCREEN, 2);
pubclass.exitCommand = new Command('编辑', Command.EXIT, 1);
//添加监听
this.addCommand(pubclass.exitCommand);
this.addCommand(pubclass.selectCommand);
this.setCommandListener(this);
}
//用户列表
public void PersonList() {
RecordStore rs = null;
rs = pubclass.Open();
try {
byte[] data;
//匹配
RecordFilter rf = new nameFilter();
//建立枚举,取出记录
RecordEnumeration re = rs.enumerateRecords(rf, null, false);
//判断是否又记录
if (re.hasNextElement()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -