[J2ME] 基本架構架構

來源:互聯網
上載者:User

標籤:des   style   blog   http   java   color   io   2014   

 

 1 import javax.microedition.lcdui.Command; 2 import javax.microedition.lcdui.CommandListener; 3 import javax.microedition.lcdui.Display; 4 import javax.microedition.lcdui.Displayable; 5 import javax.microedition.lcdui.TextBox; 6 import javax.microedition.midlet.MIDlet; 7 import javax.microedition.midlet.MIDletStateChangeException; 8  9 10 public class main extends MIDlet implements CommandListener {11 12     private Command exitCom;13     private Display ds;14     private TextBox tb;15     16     //建構函式17     public main() {18         // TODO Auto-generated constructor stub19         ds=Display.getDisplay(this);//建立Display類一個實體20         exitCom=new Command("Exit",Command.EXIT,1);//建立Command對象一個實體,並設定Exit命令用於退出這個MIDlet21         tb=new TextBox("Hellow MIDlet","Hellow World",15,0);//建立用來輸出東西的TextBox對象22         tb.addCommand(exitCom);//使Command對象和TextBox關聯起來23         tb.setCommandListener(this);//當TextBox顯示在螢幕上時,使CommandListener響應發生的事件24     }25 26     protected void destroyApp(boolean arg0) throws MIDletStateChangeException {27         // TODO Auto-generated method stub28         29     }30 31     //當系統要求MIDlet暫停時調用32     protected void pauseApp() {33         // TODO Auto-generated method stub34 35     }36 37     //第一次啟動或者暫停後重啟時由系統調用startApp()方法38     protected void startApp() throws MIDletStateChangeException {39         // TODO Auto-generated method stub40         ds.setCurrent(tb);//將建構函式中的TextBox設定為當前的螢幕41     }42 43     //使用者觸發任何Command是,做出回應,系統會自動調用這個方法44     public void commandAction(Command arg0, Displayable arg1) {45         // TODO Auto-generated method stub46         if(arg0==exitCom){47             try {48                 destroyApp(false);49                 notifyDestroyed();50             } catch (MIDletStateChangeException e) {51                 // TODO Auto-generated catch block52                 e.printStackTrace();53             }54         }55     }56 57 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.