国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

J2ME學習筆記(4)—用MIDP API開發MIDlets

2019-11-17 06:23:43
字體:
來源:轉載
供稿:網友

  1.MIDP中的特定類和接口
  1) javax.microedition.midlet-----是最內層的包,只包含一個MIDlet類,它為MIDP應用提供了基本功能開支
  
  2) javax.microedition.io-----包括HTTPConnection接口,通過這個接口,MIDlet設備可訪問Web中的數據
  
  3) javax.microedition.lcdui(Liquid Crystal Display User Interface液晶顯示用戶界面)-----對GUI組件提供支持,有與java.awt同樣的功能,javax.microedition.lcdui包中的類和接口更適用與小屏幕的手持設備.
  
  4) javax.microedition.rms(記錄治理系統)-----支持數據庫系統的不同類和接口,它們隨后存儲和檢索MIDlet所用的數據
  
  2. 一個實例:
  1) 任務陳述-----SaveMyMoney銀行的移動應用系統第一個屏幕顯示歡迎消息,第二個屏幕上應該顯示當前日期,當前時間,總的內存,以及自由內存
  
  2) 實現代碼如下:
  
  import javax.microedition.midlet.*;
  
  import javax.microedition.lcdui.*;
  
  import java.util.*;
  
  public class MB extends MIDlet implements CommandListener
  
  {
      Display display;
  
      Form form1;
  
      Form form2;
  
      Ticker ticker1;
  
      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
  
      {
         display = Display.getDisplay(this);
  
         ticker1=new Ticker("Welcome to the World of Mobile Banking!");
  
         form1 = new Form("SaveMyMoney");
  
         form2 = new Form("INFORMATION");
  
  
  
  Calendar calendar1 = Calendar.getInstance();
  
  int date=calendar1.get(Calendar.MONTH);
  
        String date1 = Integer.toString (calendar1.get(Calendar.DAY_OF_MONTH)) + " " +
  
                  Integer.toString(calendar1.get(Calendar.YEAR));
  
   String time = Integer.toString(calendar1.get(Calendar.HOUR_OF_DAY)) + ":" +
  
           Integer.toString(calendar1.get(Calendar.MINUTE)) + ":" +
  
           Integer.toString(calendar1.get(Calendar.SECOND));
  
  Runtime runMemory = Runtime.getRuntime();
  
        String total_Memory = Long.toString(runMemory.totalMemory());
  
         String free_Memory = Long.toString(runMemory.freeMemory());
  
  String month =" 0";
  
  switch(date)
  
  {
             case 0: month="January";break;
  
             case 1: month="February";break;
  
             case 2: month="March";break;
  
             case 3: month="A  
             case 4: month="May";break;
  
             case 5: month="June";break;
  
             case 6: month="July";break;
  
             case 7: month="August";break;
  
             case 8: month="September";break;
  
             case 9: month="October";break;
  
             case 10: month="November";break;
  
             case 11: month="December";break;
  
  }
         StringItem strItem = new StringItem("Welcome to  SaveMyMoney Bank!", "");
  
         form1.append(strItem);
  
         form2.append(new StringItem(" ", "DATE:         "+ month +",")) ;
  
         form2.append(date1);
  
         form2.append(new StringItem(" ", "TIME:         " + time));
  
         form2.append(new StringItem(" ", "Total Memory:   " + total_Memory));       
  
         form2.append(new StringItem(" ", "Free Memory:   " + free_Memory));
  
         form1.addCommand(exitCommand);
  
         form1.addCommand(okCommand);
  
         form1.setCommandListener(this);
  
         form1.setTicker(ticker1);
  
         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);
  
         display.setCurrent(form2);
  
      }
  
      public void commandAction(Command c, Displayable d)
  
      {
          String label = c.getLabel();
  
          if (label.equals("Exit"))
  
          {
  
              destroyApp(true);
  
          }
  
          else if (label.equals("Back"))
  
          {
  
               // go back to Form1
  
                 showForm1();
  
            }
  
          else
  
         {
  
             showForm2();
         }
     }
  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吕梁市| 原平市| 嘉定区| 泉州市| 荔波县| 绵竹市| 施秉县| 裕民县| 韶山市| 荔波县| 图木舒克市| 浦东新区| 荣成市| 泸州市| 贵南县| 瑞丽市| 兴和县| 临泉县| 会泽县| 八宿县| 瑞丽市| 贵溪市| 新邵县| 乌恰县| 连城县| 平泉县| 十堰市| 紫阳县| 白玉县| 略阳县| 青河县| 云南省| 三明市| 广宗县| 犍为县| 河北区| 石泉县| 定西市| 临武县| 当雄县| 赫章县|