`
wo_deqing
  • 浏览: 59956 次
文章分类
社区版块
存档分类
最新评论

j2me (基本界面和Command

阅读更多
rm);<wbr><br><span style="font-size:12px; line-height:1.3em">2.</span><wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><span style="font-size:12px"><span style="font-size:12px; line-height:1.3em">按钮的添加</span><wbr><br><span style="font-size:12px; line-height:1.3em">用的是Command的构造函数</span><wbr><br></wbr></wbr></span><strong><wbr><u><span style="color:#0000FF">Command</span></u><wbr></wbr></wbr></strong><wbr><span style="font-family:宋体; line-height:1.3em">(</span><wbr><u><span style="color:#0000FF">String</span></u><wbr><span style="font-family:宋体; line-height:1.3em">label, int commandType, int priority)</span><wbr><br><span style="font-size:12px"><span style="font-size:12px; line-height:1.3em">写出来格式为</span><wbr><br></wbr></span><strong><wbr>private</wbr></strong><wbr>Command comdel=<strong><wbr>new</wbr></strong><wbr> Command("删除该号码",Command.SCREEN ,1);<br> 3.<wbr><wbr><wbr><wbr><wbr><wbr><strong><wbr>将</wbr></strong><wbr><strong><wbr>Command</wbr></strong><wbr><strong><wbr>添加到界面上用得的</wbr></strong><wbr><wbr><wbr><br> 格式为<wbr><wbr><wbr><wbr><strong><wbr><u><span style="color:#0000FF">addCommand</span></u><wbr></wbr></wbr></strong><wbr><span style="font-family:宋体; line-height:1.3em">(</span><wbr><u><span style="color:#0000FF">Command</span></u><wbr><span style="font-family:宋体; line-height:1.3em">cmd)</span><wbr><br><wbr><wbr>程序代码<wbr><wbr>frm.addCommand(comdel);<wbr><wbr>//frm为前面声明的Form<br><br><br><span style="font-size:12px"><span style="font-size:12px; line-height:1.3em">左边只显示一个Command 顺序是 BACK EXITCANCEL STOP</span><wbr><br><span style="font-size:12px; line-height:1.3em">右边显示的顺序是<wbr><wbr>ITEMSCREEN OK HELP</wbr></wbr></span> <wbr><br><span style="font-size:12px; line-height:1.3em">其中左边能出现的部分在右边的显示顺序是从上往下的即BACK在最左边时在右边的排列顺序是ITEMSCREEN OK HELP EXIT CANCEL STOP</span><wbr><br><span style="font-size:12px; line-height:1.3em">代码为:</span><wbr><br></wbr></wbr></wbr></wbr></span><strong><wbr>import</wbr></strong><wbr>javax.microedition.lcdui.Command;<br><strong><wbr>import</wbr></strong><wbr> javax.microedition.lcdui.Display;<br><strong><wbr>import</wbr></strong><wbr> javax.microedition.lcdui.Form;<br><strong><wbr>import</wbr></strong><wbr> javax.microedition.midlet.MIDlet;<br><strong><wbr>import</wbr></strong><wbr>javax.microedition.midlet.MIDletStateChangeExcepti<wbr>on;<br><strong><wbr>public</wbr></strong><wbr><strong><wbr>class</wbr></strong><wbr> pro2<strong><wbr>extends</wbr></strong><wbr> MIDlet {<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Form frm2= <strong><wbr>new</wbr></strong><wbr> Form ("请输入相关操作");<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Display dis;<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command SCREEN=<strong><wbr>new</wbr></strong><wbr>Command("SCREEN",Command.<em><wbr>SCREEN</wbr></em><wbr>,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command OK=<strong><wbr>new</wbr></strong><wbr>Command("OK",Command.<em><wbr>OK</wbr></em><wbr><wbr><wbr>,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command ITEM=<strong><wbr>new</wbr></strong><wbr>Command("ITEM",Command.<em><wbr>ITEM</wbr></em><wbr> ,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command HELP=<strong><wbr>new</wbr></strong><wbr>Command("HELP",Command.<em><wbr>HELP</wbr></em><wbr> ,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command STOP=<strong><wbr>new</wbr></strong><wbr>Command("STOP",Command.<em><wbr>STOP</wbr></em><wbr> ,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command EXIT=<strong><wbr>new</wbr></strong><wbr>Command("EXIT",Command.<em><wbr>EXIT</wbr></em><wbr> ,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command BACK=<strong><wbr>new</wbr></strong><wbr>Command("BACk",Command.<em><wbr>BACK</wbr></em><wbr><wbr><wbr>,1);<br><wbr><wbr><wbr><wbr><strong><wbr>private</wbr></strong><wbr>Command CANCEL =<strong><wbr>new</wbr></strong><wbr> Command("CANCEL",Command.<em><wbr>CANCEL</wbr></em><wbr><wbr><wbr>,1);<br><wbr><wbr><wbr><wbr><strong><wbr>public</wbr></strong><wbr>pro2() {<br><wbr><wbr><wbr><wbr>dis=Display.<em><wbr>getDisplay</wbr></em><wbr>(<strong><wbr>this</wbr></strong><wbr>);<br><wbr><wbr><wbr><wbr>dis.setCurrent(frm2);<br><wbr><wbr><wbr><wbr>frm2.addCommand(SCREEN);<br><wbr><wbr><wbr><wbr>frm2.addCommand(OK);<br><wbr><wbr><wbr><wbr>frm2.addCommand(ITEM);<br><wbr><wbr><wbr><wbr>frm2.addCommand(HELP);<br><wbr><wbr><wbr><wbr>frm2.addCommand(BACK);<br><wbr><wbr><wbr><wbr>frm2.addCommand(STOP);<br><wbr><wbr><wbr><wbr>frm2.addCommand(EXIT);<br><wbr><wbr><wbr><wbr>frm2.addCommand(CANCEL);<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><strong><wbr>protected</wbr></strong><wbr><strong><wbr>void</wbr></strong><wbr> startApp() <strong><wbr>throws</wbr></strong><wbr>MIDletStateChangeExcepti<wbr>on {<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><strong><wbr>protected</wbr></strong><wbr><strong><wbr>void</wbr></strong><wbr> pauseApp() {<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><strong><wbr>protected</wbr></strong><wbr><strong><wbr>void</wbr></strong><wbr> destroyApp(<strong><wbr>boolean</wbr></strong><wbr>arg0) <strong><wbr>throws</wbr></strong><wbr> MIDletStateChangeExcepti<wbr>on{}<br> }<br> 命令按钮的响应:<wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><br> 编写一个类Commandope来实现<u><wbr>CommandListener<wbr><wbr></wbr></wbr></wbr></u><wbr><br><wbr><wbr><wbr><wbr><strong><wbr>class</wbr></strong><wbr>Commandope <strong><wbr>implements</wbr></strong><wbr> CommandListener因为Commandope实现的是一个接口故将里面的函数重写一遍<wbr><wbr><wbr><wbr><br><strong><wbr>public</wbr></strong><wbr><strong><wbr>void</wbr></strong><wbr>commandAction(Command c, Displayable d) {<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>System.<em><wbr>out</wbr></em><wbr>.println("按钮选择");<br><wbr><wbr><wbr><wbr><wbr><wbr>}<br> 将Commandope类与 Diaplayavle绑定在startApp函数中输入<wbr><wbr><wbr><wbr>frm.setCommandListener(<strong><wbr>new</wbr></strong><wbr><u><wbr>Commandope</wbr></u><wbr>() );<br><br><br><wbr><wbr>将MIDlet实现<wbr><wbr><u><wbr></wbr></u></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics