新聞中心
你對(duì)J2ME中ITEM類(lèi)用法是否熟悉,這里和大家簡(jiǎn)單分享一下,為了便于大家理解通過(guò)圖里向大家解釋?zhuān)嘈疟疚慕榻B一定會(huì)讓你有所收獲。

成都創(chuàng)新互聯(lián)公司是專(zhuān)業(yè)的涪城網(wǎng)站建設(shè)公司,涪城接單;提供網(wǎng)站建設(shè)、網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行涪城網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
J2ME中ITEM類(lèi)用法
一、基本知識(shí)
1、ITEM類(lèi)是Form類(lèi)的派生類(lèi)。
2、通過(guò)改變ITEM類(lèi)的派生類(lèi)的實(shí)例的狀態(tài),用戶(hù)可以和應(yīng)用程序進(jìn)行交互。
3、ITEM類(lèi)StateChanged方法和普通觸發(fā)器不同,在用戶(hù)引起狀態(tài)變化時(shí)自動(dòng)調(diào)用的操作,程序本身引起的不會(huì)調(diào)用。
二、創(chuàng)建實(shí)踐
1、以ChoiceGroup的應(yīng)用為例,所有應(yīng)用ITEM類(lèi)的MIDlet如果要處理ITEM類(lèi)的狀態(tài)變化必須重寫(xiě)ITEM類(lèi)StateChanged方法
2、實(shí)際運(yùn)行效果圖
3、NETBEANS設(shè)計(jì)器的設(shè)計(jì)
#p#
4、代碼(NETBEANS生成的大部分框架,筆者修改了其中幾行,增加了ITEM類(lèi)StateChanged方法)
- packagehello;
- importjavax.microedition.midlet.*;
- importjavax.microedition.lcdui.*;
- publicclassHelloMIDletextendsMIDletimplementsCommandListener,
- ITEM類(lèi)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
- }
- //
- //重寫(xiě)ITEM類(lèi)StateChanged方法
- publicvoidITEM類(lèi)StateChanged(ITEM類(lèi)ITEM類(lèi)){
- //writepre-actionusercodehere
- if(ITEM類(lèi)==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類(lèi)[]{getWeather_CG()});
- form.addCommand(getExitCommand());
- form.setCommandListener(this);
- //增加初始天氣選擇情況顯示
- form.setTitle("你選擇了晴天");
- //增加ITEM類(lèi)的監(jiān)聽(tīng)器
- form.setITEM類(lèi)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類(lèi).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){
- }
- }
網(wǎng)站題目:J2ME中ITEM類(lèi)用法實(shí)例解析
網(wǎng)頁(yè)網(wǎng)址:http://www.5511xx.com/article/dhedesh.html


咨詢(xún)
建站咨詢(xún)
