J2ME学习笔记(三)-----学习MIDlets

处理MIDlets

1.       MIDlet是使用MIDP特征和CLDC配置的MIDlet应用

1).MIDlet是打包成JAD(JAVA描述符)文件的Java类文件

2).MIDlet运行在已安装于MIDP设备上的Application Management Software(应用管理软件AMS).AMS提供KVMMIDlets的环境

3).MIDlet是在支持CLDCMIDP的手持设备中使用.

 

2.       MIDlet的生命周期()

 

3.       开发MIDlets实例

1).任务陈述-----SaveMyMoney移动银行应用的第一个屏幕上要显示的消息为”Welcome to    SaveMyMoney Bank!”,屏幕顶部有一个显示消息"Welcome to the World of Mobile Banking!"的滚动文本;

第二个屏幕上要显示的消息为"Dear Customer,        , You can view your personal account information by entering your PIN number and sending it to the number 9002. If you have not received the PIN number, please contact us at our Head Office."屏幕顶部有一个显示消息"Note: Your PIN number has been sent to you at your mailing address."的滚动文本

 

2).代码如下-----

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

//需要实现lcdui类中的CommandListener接口

public class MB extends MIDlet implements CommandListener

{

       //Display类管理显示和用户的输入

       Display display;

       Form form1;

       Form form2;

       //定义两个滚动条ticker1,ticker2

       Ticker ticker1;

       Ticker ticker2;

       static final Command okCommand = new Command("Info",Command.OK,1);

       static final Command backCommand = new Command("Back",Command.BACK,0);

       static final Command exitCommand = new Command("Exit", Command.STOP, 2);

       public MB()

       {

       }

       public void startApp() throws MIDletStateChangeException

       {

              ticker1 = new Ticker("Welcome to the World of Mobile Banking!");

              ticker2 = new Ticker("Note: Your PIN number has been sent to you at your mailing address.");

             

              display = Display.getDisplay(this);

              form1 = new Form("SaveMyMoney");

              form2 = new Form("CUSTOMER CARE");

              StringItem strItem = new StringItem("Welcome to    SaveMyMoney Bank!", "");

              StringItem strItem1 = new StringItem("Dear Customer,        ", "You can view your personal account information by entering your PIN number and sending it to the number 9002. If you have not received the PIN number, please contact us at our Head Office.");

              form1.append(strItem);

              form2.append(strItem1);

              //把命令加入到屏幕,第一个屏幕的左软键是Exit,右软键是OK

              form1.addCommand(exitCommand);

              form1.addCommand(okCommand);

              //监听

              form1.setCommandListener(this);

              form1.setTicker(ticker1);

              //设置主屏幕的当前显示为Form1

              display.setCurrent(form1);

       }

       public void pauseApp()

       {

       }

       public void destroyApp(boolean unconditional)

       {

              notifyDestroyed();

       }

       public void showForm1()

       {

              form1.addCommand(exitCommand);

              form1.addCommand(okCommand);

              form1.setCommandListener(this);

              display.setCurrent(form1);

       }

       public void showForm2()

       {

              form2.addCommand(exitCommand);

              form2.addCommand(backCommand);

              form2.setCommandListener(this);

              form2.setTicker(ticker2);

              display.setCurrent(form2);

      

       }

       public void commandAction(Command cmd, Displayable displayable)

       {

              String label = cmd.getLabel();

              if (label.equals("Exit"))

              {

                     //调用撤消MIDlet的动作并退出此应用

              destroyApp(true);

              }

              else if (label.equals("Back"))

              {

// go back to Form1

                     showForm1();

              }

              else

              {

                     showForm2();

              }

       }

}

 测试效果如下:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值