📄 midpapplication.java~1~
字号:
package wh;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
public class MIDPApplication extends MIDlet
implements CommandListener{
Ticker newsTicker;
private List menuList; //主菜单
private List commList; //通讯簿菜单
private Command enterCommand; //进入
private Command exitCommand; //离开
private Command execCommand; //执行
private Command menuCommand; //主目录
private Command commCommand; //通讯簿
private Command configCommand; //确定
private Command backCommand; //返回
private Command saveCommand; //存储
Form queryForm = null;
Form modificationForm = null;
Form deleteForm = null;
TextField nameField;
TextField EMailField;
TextField ageField;
Image aImage;
ImageItem imageItem;
String[] menuItem ={"通讯簿","关于","退出"};
String[] commItem ={"新增","查询","修改","删除"};
Image[] menuImage = {
createImage("/Sokoban.png"),
createImage("/Sokoban.png"),
createImage("/Sokoban.png")
};
//The display for this MIDlet
private Display display;
private String currentScreen = "";
public static String criteria = "";
private int deleteID = 0;
private int modificationID = 0;
public MIDPApplication() {
display = Display.getDisplay(this);
newsTicker = new Ticker("欢迎老师检查作业!");
enterCommand = new Command("进入",Command.OK,1);
menuCommand = new Command("主目录",Command.SCREEN, 1);
commCommand = new Command("通讯簿",Command.SCREEN, 1);
commCommand = new Command("关于",Command.SCREEN,2);
execCommand = new Command("执行",Command.OK, 1);
exitCommand = new Command("离开", Command.EXIT, 1);
configCommand = new Command("确定",Command.OK,1);
backCommand = new Command("返回",Command.BACK,1);
try
{
aImage=Image.createImage("/wh.png");
}
catch(Exception e)
{}
imageItem=new ImageItem( null,aImage,ImageItem.LAYOUT_CENTER,"sorry");
}
public void startApp() {
Form aForm=new Form("个人相片");
aForm.append(aImage);
aForm.append(imageItem);
aForm.addCommand(enterCommand);
aForm.addCommand(exitCommand);
aForm.setCommandListener(this);
display.setCurrent(aForm);
menuList = new List(null,List.IMPLICIT,menuItem,menuImage);
menuList.setTicker(newsTicker);
menuList.addCommand(exitCommand);
menuList.setCommandListener(this);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if(c==enterCommand){
display.setCurrent(menuList);
currentScreen="主目录";
}
if(c==List.SELECT_COMMAND){
if(currentScreen=="主目录"){
int itemIndex = menuList.getSelectedIndex();
switch(itemIndex){
case 0: {
doCommunication();
break;
}
case 1: {
Alert aAlert;
aAlert =new Alert ("我的信息","姓名:万慧 \n学号:02221519\n网通(1)班",null,
AlertType.INFO);
aAlert.setTimeout(6000);
display.setCurrent(aAlert);
break;
}
case 2:{
doexit();
break;
}
}
}
else if(currentScreen=="通讯簿"){
int itemIndex = commList.getSelectedIndex();
switch(itemIndex){
case 0:{
doAppend(); //添加信息
break;
}
case 1:{
doQuery(); //查询信息
break;
}
case 2:{
doModification();//修改信息
break;
}
case 3:{
doDelete(); //删除信息
break;
}
}
}
}
if(c==configCommand)
{
int itemIndex = commList.getSelectedIndex();
switch(itemIndex){
case 0:{
doAppend(); //添加信息
break;
}
case 1:{
doQuery(); //查询信息
break;
}
case 2:{
doModification();//修改信息
break;
}
case 3:{
doDelete(); //删除信息
break;
}
}
}
if(c==commCommand){
doCommunication();
}
if(c==menuCommand){
doMenu();
}
if(c==execCommand){
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);
EMailField = new TextField("E Mail",null,30,TextField.EMAILADDR);
ageField = new TextField("年龄",null,3,TextField.NUMERIC);
saveCommand = new Command("存储",Command.SCREEN,1);
modificationForm.addCommand(saveCommand);
modificationForm.removeCommand(execCommand);
modificationForm.append(EMailField);
modificationForm.append(ageField);
}
else{
}
}
}
//------存储通讯簿的数据
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -