⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbookmidlet.java

📁 手机通信录程序使用JBuilder2006开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package AddressBook;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.rms.*;
import java.util.Vector;
import javax.microedition.io.*;
import java.util.Enumeration;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
/**AddressBookMIDlet.java
 * 演示如何使用RMS中记录存储的管理
 * 记录的管理和记录的查询排序
 * 结合lcdui界面库使用GUI来操作RMS
 */
public class AddressBookMIDlet extends MIDlet implements CommandListener{
    private Display display=null;            //声明Display变量
    public Image image;
   private List menusee=null;
    Command search=null;                     //声明查询按钮
    Command quit=null;                       //声明关闭按钮
    Command delete=null;                     //声明删除按钮
    Command addnow=null;                     //声明增加按钮
    Command edit=null;                       //声明修改按钮
    Command mainmenu=null;                   //声明主菜单按钮
    Command info=null;                        //声明详情按钮
    Command see=null;
    Command searchback=null;
    Command deleteback=null;
    Command addnowback=null;
    Command editback=null;
    Command infoback=null;


    List menu=null;                          //声明列表菜单
    Form ui_form=null;                       //声明Form容器
    StringItem si=null;                      //条目字符串
    TextField name=null;                     //声明输入名字的TextField
    TextField phone=null;                    //声明输入电话号码的TextField
    TextField familyphone=null;
    TextField email=null;
    TextField nameForEdit=null;              //声明输入需要修改的名字的TextField


    List users=null;       //通信录列表
    int searchway=0;        //通信录查询方式  姓名查询为1,通信录列表查询为2 其它为0
    RecordStore recordStore=null;            //声明记录存储



    public AddressBookMIDlet() {             //构造函数,执行必要的初始化工作
        //用户界面初始化
        display=Display.getDisplay(this);

        quit=new Command("关闭",Command.EXIT,3);
        search=new Command("查询",Command.SCREEN,2);
        delete=new Command("删除",Command.SCREEN,2);
        addnow=new Command("增加",Command.SCREEN,2);
        edit=new Command("修改",Command.SCREEN,2);
        mainmenu=new Command("主菜单",Command.SCREEN,2);
        see=new Command("查看",Command.SCREEN,2);
        info=new Command("详情",Command.SCREEN,2);
        searchback=new Command("返回",Command.BACK,1);
        deleteback=new Command("返回",Command.BACK,1);
        addnowback=new Command("返回",Command.BACK,1);
        editback=new Command("返回",Command.BACK,1);
        infoback=new Command("返回",Command.BACK,1);

        //记录存储初始化
        try{
            recordStore=RecordStore.openRecordStore("addresses",true);
        }catch(RecordStoreException rse){
            rse.printStackTrace();
        }
    }



    //startApp,设置菜单选项及其监听
    public void startApp() {
      image=createImage("//image/ff.gif");
         Alert splashScreen;
          if (image==null){
           splashScreen = new Alert("开机图片出错",null,null,AlertType.INFO);
             splashScreen.setTimeout(100);
         }else{
          splashScreen = new Alert("开机画面",null,image,AlertType.INFO);
          }

        menu=new List("通信录",List.IMPLICIT);
        menu.append("查询联系人",null);
        menu.append("添加联系人",null);
        menu.append("删除联系人",null);
        menu.append("修改联关系人",null);
        menu.append("查看联系人",null);
        menu.append("关闭",null);



        menu.setCommandListener(this);
       Display.getDisplay(this).setCurrent( splashScreen,menu);

    }


    //查询用户界面
    void searchScreen(){
        ui_form=new Form("电话本查询");
        name=new TextField("姓名查询","",50,0);
         searchway=1;
        ui_form.append(name);
        ui_form.addCommand(search);
        ui_form.addCommand(mainmenu);
        ui_form.addCommand(quit);


        ui_form.setCommandListener(this);

        display.setCurrent(ui_form);

    }



    //增加记录的用户界面
    void addScreen(){
        ui_form=new Form("添加联系人");
        name=new TextField("姓名","",50,TextField.ANY);
        ui_form.append(name);
        phone=new TextField("手机号码","",50,TextField.PHONENUMBER);
        ui_form.append(phone);
        familyphone=new TextField("固定号码","",50,TextField.PHONENUMBER);
        ui_form.append(familyphone);
        email=new TextField("电子邮件",null,25,TextField.EMAILADDR);
        ui_form.append(email);



        ui_form.addCommand(addnow);
        ui_form.addCommand(mainmenu);
        ui_form.addCommand(quit);

        ui_form.setCommandListener(this);

        display.setCurrent(ui_form);

    }


    //修改记录的用户界面
    void editScreen(){
        ui_form=new Form("修改");

        nameForEdit=new TextField("需要修改的姓名","",50,0);
        ui_form.append(nameForEdit);

        name=new TextField("姓名","",50,0);
        ui_form.append(name);

        phone=new TextField("手机号码","",50,0);
        ui_form.append(phone);

        familyphone=new TextField("固定号码","",50,0);
        ui_form.append(familyphone);

        email=new TextField("电子邮件",null,25,TextField.EMAILADDR);
        ui_form.append(email);

        ui_form.addCommand(edit);
        ui_form.addCommand(mainmenu);
        ui_form.addCommand(quit);

        ui_form.setCommandListener(this);

        display.setCurrent(ui_form);

    }

    //删除一条记录的用户界面
    void deleteScreen(){
        ui_form=new Form("删除");

        name=new TextField("姓名","",50,0);
        ui_form.append(name);



        ui_form.addCommand(delete);
        ui_form.addCommand(mainmenu);
        ui_form.addCommand(quit);
        ui_form.setCommandListener(this);

        display.setCurrent(ui_form);

    }

    void seeScreen(){
     // menusee=new List("联系人列表",List.IMPLICIT);
      // ui_form=new Form("联系人列表");
       //menusee.append(address_see(),List.IMPLICIT);
    address_see();

      /*
         ui_form.addCommand(see);
         ui_form.addCommand(mainmenu);
         ui_form.addCommand(quit);

         ui_form.setCommandListener(this);
         display.setCurrent(ui_form);
*/
    }

   /*void infoScreen(){
    ui_form=new Form("详细信息");


    ui_form.addCommand(mainmenu);
    ui_form.addCommand(infoback);
   }*/

    //pauseApp 重置menu
    public void pauseApp() {
        menu=null;
    }

    //destroyApp 关闭应用程序
    public void destroyApp(boolean unconditional) {
        menu=null;
        notifyDestroyed();
    }

    //事件处理
    public void commandAction(Command c,Displayable d){
        if(c==quit){                          //按下关闭按钮,触发相应事件处理
            try{
                close();                      //关闭记录存储
            }catch(RecordStoreException rse){
                rse.printStackTrace();        //销毁应用程序,触发相应事件处理
            }
            destroyApp(true);
        }
        else if(c==search){                   //按下查询按钮,触发相应事件处理
         //  System.out.println(users.getSelectedIndex());
            String temp_search;
            if(searchway==1) temp_search=name.getString();   //获取要查询的姓名
            else if(searchway==2) temp_search=users.getString(users.getSelectedIndex());
            else temp_search="";
            address_search(temp_search);    //调用查询方法
            searchway=0;
        }
        else if(c==searchback){
          this.searchScreen();
        }
        else if(c==see){
          //String temp_see;
          address_see();
        }
        else if(c==info){
          String temp_info=name.getString();
          address_info(temp_info);
        }
        else if(c==edit){                     //按下编辑按钮,触发相应事件处理
            String temp_nameForEdit=nameForEdit.getString();
            String temp_name=name.getString();
            String temp_phone=phone.getString();
            String temp_familyphone=familyphone.getString();
            String temp_email=email.getString();
            address_edit(temp_nameForEdit,temp_name,temp_phone,temp_familyphone,temp_email);   //调用修改方法
        }
        else if(c==editback){
          this.editScreen();
        }
        else if(c==mainmenu){                 //按下主菜单,触发相应事件处理
            startApp();                       //重置
        }
        else if(c==delete){                   //按下删除按钮,触发相应事件处理
            String temp_delete=name.getString();  //获取要删除的姓名
            address_del(temp_delete);         //调用删除方法
        }
        else if(c==deleteback){
          this.deleteScreen();
        }
        else if(c==addnow){                   //按下增加按钮,触发相应事件处理
            String temp_name=name.getString();  //获取增加的姓名
            String temp_phone=phone.getString();//获取增加的电话号码
            String temp_familyphone=familyphone.getString();
            String temp_email=email.getString();
            address_add(temp_name,temp_phone,temp_familyphone,temp_email);  //调用增加方法
        }
        else if(c==addnowback){

          this.addScreen();
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -