📄 tongxunbu.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.rms.*;
public class TongXunBu extends MIDlet implements CommandListener
{
Ticker newsTicker;
private List menuList;
private List commList;
private List jishiList;
private Command exitCommand;
private Command execCommand;
private Command menuCommand;
private Command commCommand;
private Command jishiCommand;
private Command saveCommand;
Form queryForm=null;
Form modificationForm=null;
Form deleteForm=null;
Form jqueryForm=null;
Form jmodificationForm=null;
Form jdeleteForm=null;
DateField dateField;
TextField msgField;
TextField keyField;
TextField nameField;
TextField ageField;
TextField telField;
TextField qqField;
TextField EMailField;
TextField addressField;
String[] menuItem={"通讯簿","记事本"};
String[] commItem={"新增","查询","修改","删除"};
String[] jishiItem={"记事","查看","修改","删除"};
Image[] menuImage={createImage("/tongxun.png"),
createImage("/jishi.png")};
private Display display;
private String currentScreen="";
public static String criteria="";
private int modificationID=0;
private int deleteID=0;
public TongXunBu(){
display=Display.getDisplay(this);
newsTicker=new Ticker("");
exitCommand=new Command("离开",Command.EXIT,1);
execCommand=new Command("执行",Command.OK,1);
menuCommand=new Command("主目录",Command.SCREEN,1);
commCommand=new Command("通讯簿",Command.SCREEN,1);
jishiCommand=new Command("记事本",Command.SCREEN,1);
}
//进入进程
public void startApp(){
doCommunication();
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
//命令设置
public void commandAction(Command c,Displayable s){
if(c==exitCommand){
destroyApp(false);
notifyDestroyed();
}
if(c==List.SELECT_COMMAND){
if(currentScreen=="通讯簿"){
int itemIndex=commList.getSelectedIndex();
switch(itemIndex){
case 0:{
doAppend();
break;
}
case 1:{
doQuery();
break;
}
case 2:{
doModification();
break;
}
case 3:{
doDelete();
break;
}
}
}
else{
}
}
if(c==menuCommand){
display.setCurrent(menuList);
currentScreen="主目录";
}
if(c==commCommand){
doCommunication();
}
if(c==jishiCommand){
dojishi();
}
if(c==menuCommand){
doMenu();
}
if(c==execCommand){
//******** if(currentScreen=="记事簿"){
if(currentScreen=="通讯簿查询"){
this.criteria=nameField.getString();
doQueryPerson();
queryForm=null;
}
if(currentScreen=="通讯簿删除"){
doQueryPerson();
doDeletePerson(this.deleteID);
}
if(currentScreen=="通讯簿修改"){
modificationID=0;
doQueryPerson();
if(!nameField.getString().equals("无此数据")){
System.out.println("i am here"+":"+modificationID);
ageField=new TextField("生日",null,30,TextField.ANY);
telField=new TextField("电话",null,30,TextField.ANY);
qqField=new TextField("QQ",null,30,TextField.ANY);
EMailField=new TextField("E Mail",null,30,TextField.EMAILADDR);
addressField=new TextField("地址",null,50,TextField.ANY);
saveCommand=new Command("存储",Command.SCREEN,1);
modificationForm.addCommand(saveCommand);
modificationForm.removeCommand(execCommand);
modificationForm.append(ageField);
modificationForm.append(telField);
modificationForm.append(qqField);
modificationForm.append(EMailField);
modificationForm.append(addressField);
}
else{
}
}
}
if(c==saveCommand)
doSave();
}
//读取图片
private Image createImage(String name){
Image aImage=null;
try{
aImage=Image.createImage(name);
}
catch(IOException e){
}
return aImage;
}
//主菜单
private void doMenu(){
currentScreen="主目录";
display.setCurrent(menuList);
}
//通讯簿菜单
private void doCommunication(){
//************ Image[] commIcon={};
commList=new List("通讯簿",List.IMPLICIT,commItem,null);
commList.addCommand(exitCommand);
commList.setCommandListener(this);
currentScreen="通讯簿";
display.setCurrent(commList);
}
//记事本菜单
private void dojishi(){
// ************ Image[] commIcon={};
jishiList=new List("记事本",List.IMPLICIT,jishiItem,null);
jishiList.addCommand(jishiCommand);
jishiList.addCommand(menuCommand);
jishiList.setCommandListener(this);
currentScreen="记事本";
display.setCurrent(jishiList);
}
// *******************
//通讯簿新增窗口
private void doAppend(){
Form appendForm=new Form("新增");
nameField=new TextField("姓名",null,8,TextField.ANY);
ageField=new TextField("生日",null,30,TextField.ANY);
telField=new TextField("电话",null,30,TextField.ANY);
qqField=new TextField("QQ",null,30,TextField.ANY);
EMailField=new TextField("E Mail",null,30,TextField.EMAILADDR);
addressField=new TextField("地址",null,50,TextField.ANY);
saveCommand=new Command("存储",Command.SCREEN,1);
appendForm.append(nameField);
appendForm.append(ageField);
appendForm.append(telField);
appendForm.append(qqField);
appendForm.append(EMailField);
appendForm.append(addressField);
appendForm.addCommand(saveCommand);
appendForm.addCommand(commCommand);
appendForm.setCommandListener(this);
currentScreen="通讯簿新增";
display.setCurrent(appendForm);
}
//通讯簿修改窗口
private void doModification(){
modificationForm=new Form("修改");
nameField=new TextField("姓名",null,8,TextField.ANY);
modificationForm.append(nameField);
modificationForm.addCommand(execCommand);
modificationForm.addCommand(commCommand);
modificationForm.setCommandListener(this);
currentScreen="通讯簿修改";
display.setCurrent(modificationForm);
}
//通讯簿查询窗口
private void doQuery(){
queryForm=new Form("查询");
nameField=new TextField("姓名",null,8,TextField.ANY);
queryForm.append(nameField);
queryForm.addCommand(execCommand);
queryForm.addCommand(commCommand);
queryForm.setCommandListener(this);
currentScreen="通讯簿查询";
display.setCurrent(queryForm);
}
//通讯簿删除窗口
private void doDelete(){
Form deleteForm=new Form("删除");
nameField=new TextField("姓名",null,8,TextField.ANY);
deleteForm.append(nameField);
deleteForm.addCommand(execCommand);
deleteForm.addCommand(commCommand);
deleteForm.setCommandListener(this);
currentScreen="通讯簿删除";
System.out.println("记录已删除");
display.setCurrent(deleteForm);
}
//通讯簿新增记录存储
private void doSave(){
RecordStore rs=null;
byte[] nameEmail=null;
boolean existingOrNot=false;
existingOrNot=existing("aperson");
if(existingOrNot){
try{
rs=RecordStore.openRecordStore("aperson",false);
}
catch(Exception e){
}
}
else{
try{
rs=RecordStore.openRecordStore("aperson",true);
}
catch(Exception e){
}
}
person aperson=null;
try{
aperson=new person();
aperson.write(nameField.getString(),
ageField.getString(),
telField.getString(),
qqField.getString(),
EMailField.getString(),
addressField.getString()
);
byte[] data=aperson.changeToByteArray();
int recordID=aperson.getRecordID();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -