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

huanghui22 2004-07-28 05:48:04
处理MIDlets
1.MIDlet是使用MIDP特征和CLDC配置的MIDlet应用
1).MIDlet是打包成JAD(JAVA描述符)文件的Java类文件
2).MIDlet运行在已安装于MIDP设备上的Application Management Software(应用管理软件AMS).AMS提供KVM和MIDlets的环境
3).MIDlet是在支持CLDC和MIDP的手持设备中使用.

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();
}
}
}


...全文
229 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
guojiafuzhuxi 2004-09-12
  • 打赏
  • 举报
回复
抄书的吧
zealVampire 2004-09-11
  • 打赏
  • 举报
回复
支持
ghost8367 2004-09-10
  • 打赏
  • 举报
回复
up
huanghui22 2004-07-28
  • 打赏
  • 举报
回复
我已经把文章放到我的blog里面去了,地址是http://blog.csdn.net/huanghui22,大家有空可以去看看,文章里面也加了贴图:)
javaCandelaboy 2004-07-28
  • 打赏
  • 举报
回复
不错,刚刚学习j2me中,就找到了这么好的一个入门程序,谢谢楼主。
mingjava 2004-07-28
  • 打赏
  • 举报
回复
为什么不写入你的blog呢
minghuitian 2004-07-28
  • 打赏
  • 举报
回复
up
贝壳鱼 2004-07-28
  • 打赏
  • 举报
回复
一楼,接分

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧