📄 messagemidlet.java
字号:
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]);
}
//全局变量ModID
private void SetGetModId() {
int itemid = this.getSelectedIndex();
SetGet.SetModId(recordIDs[itemid]);
}
//全局变量DelID
private void SetGetDelId() {
int itemid = this.getSelectedIndex();
SetGet.SetDelId(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.SetGetModId();
this.SetGetDelId();
pubclass.Return_OperateMIDLet();
}else{
AlerNone();
}
}
if(c ==pubclass.selectCommand ){
if (SetGet.GetIsTrue()){
this.SetGetId();
pubclass.Return_PersonDetailMIDlet();
}else{
AlerNone();
}
}
}
}
class nameFilter implements RecordFilter{
public boolean matches(byte[] candidate){
DataInputStream person = new DataInputStream(new ByteArrayInputStream(candidate));
String personcname = '';
try{
personcname = person.readUTF();
}
catch(Exception e){
}
PersonClass personclass = new PersonClass();
if(personcname.equals(SetGet.GetStr())) return true;
else return false;
}
}
//=========================end================================
//=========================PersonDetailMIDlet指定联系人详细信息================================
package messagemidlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class PersonDetailMIDlet extends Form implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public PersonDetailMIDlet() {
super('');
this.ConstructorList();
//构造按钮
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);
}
//构造LIST,显示详细信息
private void ConstructorList() {
try {
this.GetPersonDetail();
}
catch (RecordStoreException ex) {
}
}
//绑定对应ID数据,并显示
private void GetPersonDetail() throws RecordStoreException {
RecordStore rs = null;
//打开数据库
rs = pubclass.Open();
//建立枚举,取得对应ID的详细信息
try {
byte[] data;
RecordEnumeration re = rs.enumerateRecords(null, null, false);
data = rs.getRecord(SetGet.GetId());
//重新构造,并把byte转换为string类型
PersonClass personclass = new PersonClass();
personclass.changeFromByteArray(data);
//重新设置用户ID
int RecordId = rs.getNextRecordID();
//给对应的属性赋值
for (int i = 0; i < pubclass.persondetail.length; i++) {
this.append(pubclass.persondetail[i]);
pubclass.persondetail[i].setText(personclass.getPerson(i));
}
//设置标题为用户名
this.setTitle(personclass.getPerson(0));
}
catch (RecordStoreNotOpenException ex) {
}
}
public void commandAction(Command c, Displayable d) {
if(c == pubclass.selectCommand){
pubclass.Return_PersonListMIDLet();
}
if(c == pubclass.exitCommand){
pubclass.Return_MenuMIDLet();
}
}
}
//=========================end================================
//=========================OperateMIDlet操作联系人类(这里只有删除功能)================================
package messagemidlet;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class OperateMIDlet extends List implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public OperateMIDlet() {
super('联系人', List.IMPLICIT);
for (int i = 0; i < pubclass.operatelist.length; i++) {
this.append(pubclass.Get_OperateList(i), pubclass.createImage('/images/edit.png'));
}
//构造按钮
pubclass.operCommand = new Command('选择', Command.SCREEN, 2);
pubclass.menuCommand = new Command('主目录', Command.EXIT, 1);
//添加监听
this.addCommand(pubclass.menuCommand);
this.addCommand(pubclass.operCommand);
this.setCommandListener(this);
}
//删除指定记录
public void Del(int delid) {
PersonClass personclass = new PersonClass();
RecordStore rs = null;
rs = pubclass.Open();
try {
//判断是否又记录
if(rs.getNumRecords()<1){
pubclass.Alert('还未添加记录!返回中.......');
}else{
//bug
rs.deleteRecord(delid);
AlertInfo('删除成功!返回中.......');
}
}
catch (Exception e) {
AlertInfo('删除失败!返回中.......');
}
}
//全部删除记录
public void Delall() {
PersonClass personclass = new PersonClass();
RecordStore rs = null;
rs = pubclass.Open();
//判断是否又记录
try {
if (rs.getNumRecords() < 1) {
pubclass.Alert('还未添加记录!返回中.......');
}
else {
//构造RecordEnumeration实例,取出记录
RecordEnumeration re = rs.enumerateRecords(null, null, false);
//根据ID,循环删除
while (re.hasNextElement()) {
int recoidId = re.nextRecordId();
rs.deleteRecord(recoidId);
}
AlertInfo('删除成功!返回中.......');
}
}
catch (Exception e) {
AlertInfo('删除失败!返回中.......');
}
}
public void AlertInfo(String info){
PersonListMIDlet Personlistmidlet = new PersonListMIDlet();
pubclass.Alert(in, fo,Personlistmidlet);
}
public void commandAction(Command c, Displayable d) {
if(c ==pubclass.menuCommand ){
pubclass.Return_MenuMIDLet();
}
if(c ==pubclass.operCommand ){
int selectitem = this.getSelectedIndex();
//尽量不使用Switch,用If提高速度,虽然麻烦点,经验所得
if (selectitem == 0) {
pubclass.Return_ModifyPersonMIDlet();
}
if (selectitem == 1) {
Del(SetGet.GetDelId());
SetGet.SetDelId(0);
}
if (selectitem == 2) {
Delall();
SetGet.SetDelId(0);
}
}
}
}
//=========================end================================
//=========================ModifyPersonMIDlet修改指定联系人详细信息================================
package messagemidlet;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class ModifyPersonMIDlet extends Form implements CommandListener {
//构造公共类实例
private PubClass pubclass = new PubClass();
/** Constructor */
public ModifyPersonMIDlet() {
super('');
try {
this.GetPersonDetail();
}
catch (RecordStoreException ex) {
}
//构造按钮
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);
}
//绑定对应ID数据,并显示
private void GetPersonDetail() throws RecordStoreException {
RecordStore rs = null;
//打开数据库
rs = pubclass.Open();
//建立枚举,取得对应ID的详细信息
try {
byte[] data;
RecordEnumeration re = rs.enumerateRecords(null, null, false);
data = rs.getRecord(SetGet.GetModId());
//重新构造,并把byte转换为string类型
PersonClass personclass = new PersonClass();
personclass.changeFromByteArray(data);
//重新设置用户ID
int RecordId = rs.getNextRecordID();
//给对应的属性赋值
for (int i = 0; i < pubclass.person.length; i++) {
this.append(pubclass.person[i]);
pubclass.person[i].setString(personclass.getPerson(i));
}
//设置标题为用户名
this.setTitle('修改'+personclass.getPerson(0));
}
catch (RecordStoreNotOpenException ex) {
}
rs.closeRecordStore();
}
//修改联系人
public void UpdataPerson() {
RecordStore rs = null;
rs = pubclass.Open();
try {
//取得textfield每个直,以数组形式保存
String[] getstring = new String[pubclass.Length];
for (int i = 0; i < pubclass.Length; i++) {
getstring[i] = pubclass.person[i].getString();
}
//构造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 {
//修改记录
rs.setRecord(SetGet.GetModId(),data,0,data.length);//rs.setRecord(SetGet.GetModId(), data,0, data.length);
personclass.SetRecordID(recordId);
}
SetGet.SetModId(0);
PersonListMIDlet Personlistmidlet = new PersonListMIDlet();
pubclass.Alert('修改成功!返回中.......',Personlistmidlet);
}
catch (Exception e) {
PersonListMIDlet Personlistmidlet = new PersonListMIDlet();
pubclass.Alert('修改失败',Personlistmidlet);
}
}
public void commandAction(Command c, Displayable d) {
if(c == pubclass.exitCommand){
pubclass.Return_MenuMIDLet();
}
if(c == pubclass.okCommand){
//判断至少要填写姓名
if (pubclass.person[0].getString() == null || pubclass.person[0].getString() == '') {
pubclass.Alert('至少要填写姓名');
}
else {
this.UpdataPerson();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -