新聞中心
你對(duì)J2ME中ITEM類用法是否熟悉,這里和大家簡單分享一下,為了便于大家理解通過圖里向大家解釋,相信本文介紹一定會(huì)讓你有所收獲。

成都創(chuàng)新互聯(lián)公司是專業(yè)的涪城網(wǎng)站建設(shè)公司,涪城接單;提供網(wǎng)站建設(shè)、網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行涪城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
J2ME中ITEM類用法
一、基本知識(shí)
1、ITEM類是Form類的派生類。
2、通過改變ITEM類的派生類的實(shí)例的狀態(tài),用戶可以和應(yīng)用程序進(jìn)行交互。
3、ITEM類StateChanged方法和普通觸發(fā)器不同,在用戶引起狀態(tài)變化時(shí)自動(dòng)調(diào)用的操作,程序本身引起的不會(huì)調(diào)用。
二、創(chuàng)建實(shí)踐
1、以ChoiceGroup的應(yīng)用為例,所有應(yīng)用ITEM類的MIDlet如果要處理ITEM類的狀態(tài)變化必須重寫ITEM類StateChanged方法
2、實(shí)際運(yùn)行效果圖
3、NETBEANS設(shè)計(jì)器的設(shè)計(jì)
#p#
4、代碼(NETBEANS生成的大部分框架,筆者修改了其中幾行,增加了ITEM類StateChanged方法)
- packagehello;
- importjavax.microedition.midlet.*;
- importjavax.microedition.lcdui.*;
- publicclassHelloMIDletextendsMIDletimplementsCommandListener,
- ITEM類StateListener{
- privatebooleanmidletPaused=false;
- //
- privateCommandexitCommand;
- privateFormform;
- privateChoiceGroupweather_CG;
- //
- publicHelloMIDlet(){
- }
- //
- //
- //
- privatevoidinitialize(){
- //writepre-initializeusercodehere
- //writepost-initializeusercodehere
- }
- //
- //
- publicvoidstartMIDlet(){
- //writepre-actionusercodehere
- switchDisplayable(null,getForm());
- //writepost-actionusercodehere
- }
- //
- //
- publicvoidresumeMIDlet(){
- //writepre-actionusercodehere
- //writepost-actionusercodehere
- }
- //
- //
- publicvoidswitchDisplayable(Alertalert,
- DisplayablenextDisplayable){
- //writepre-switchusercodehere
- Displaydisplay=getDisplay();
- if(alert==null){
- display.setCurrent(nextDisplayable);
- }else{
- display.setCurrent(alert,nextDisplayable);
- }
- //writepost-switchusercodehere
- }
- //
- //
- publicvoidcommandAction(Commandcommand,
- Displayabledisplayable){
- //writepre-actionusercodehere
- if(displayable==form){
- if(command==exitCommand){
- //writepre-actionusercodehere
- exitMIDlet();
- //writepost-actionusercodehere
- }
- }
- //writepost-actionusercodehere
- }
- //
- //重寫ITEM類StateChanged方法
- publicvoidITEM類StateChanged(ITEM類ITEM類){
- //writepre-actionusercodehere
- if(ITEM類==weather_CG){
- form.setTitle("你選擇了"+weather_CG.getString
- (weather_CG.getSelectedIndex())+"天");
- //writepost-actionusercodehere
- }
- //writepost-actionusercodehere
- }
- //
- //
- publicCommandgetExitCommand(){
- if(exitCommand==null){
- //writepre-initusercodehere
- exitCommand=newCommand("\u9000\u51FA",Command.EXIT,0);
- //writepost-initusercodehere
- }
- returnexitCommand;
- }
- //
- //
- publicFormgetForm(){
- if(form==null){
- //writepre-initusercodehere
- form=newForm("Welcome",newITEM類[]{getWeather_CG()});
- form.addCommand(getExitCommand());
- form.setCommandListener(this);
- //增加初始天氣選擇情況顯示
- form.setTitle("你選擇了晴天");
- //增加ITEM類的監(jiān)聽器
- form.setITEM類StateListener(this);
- //writepost-initusercodehere
- }
- returnform;
- }
- //
- //
- publicChoiceGroupgetWeather_CG(){
- if(weather_CG==null){
- //writepre-initusercodehere
- weather_CG=newChoiceGroup
- ("\u5929\u6C14\u7C7B\u578B",Choice.EXCLUSIVE);
- weather_CG.setLayout(ImageITEM類.LAYOUT_DEFAULT);
- weather_CG.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);
- //選項(xiàng)框項(xiàng)的代碼
- weather_CG.append("晴",null);
- weather_CG.append("陰",null);
- weather_CG.append("雨",null);
- weather_CG.append("雪",null);
- weather_CG.setSelectedIndex(0,true);
- //writepost-initusercodehere
- }
- returnweather_CG;
- }
- //
- publicDisplaygetDisplay(){
- returnDisplay.getDisplay(this);
- }
- publicvoidexitMIDlet(){
- switchDisplayable(null,null);
- destroyApp(true);
- notifyDestroyed();
- }
- publicvoidstartApp(){
- if(midletPaused){
- resumeMIDlet();
- }else{
- initialize();
- startMIDlet();
- }
- midletPaused=false;
- }
- publicvoidpauseApp(){
- midletPaused=true;
- }
- publicvoiddestroyApp(booleanunconditional){
- }
- }
文章題目:J2ME中ITEM類用法實(shí)例解析
網(wǎng)址分享:http://m.5511xx.com/article/dhedesh.html


咨詢
建站咨詢
