开发J2ME低级联网应用[3]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

      public void run() {
        while (!exit) {
          synchronized(parent) {
            while(!commandAvailable) {
              try {
                parent.wait();
              }
              catch (InterruptedException e) {
              }
            }
          }
          commandAvailable = false;
     
          switch (menu.getSelectedIndex()) {
            case 0:
              getDate();
              break;
            case 1:
              exit = true;
          }
        }
        destroyApp(false);
        notifyDestroyed();
      }

    public void getDate() {
      try {
        socket =
          (StreamConnection)Connector.open(dayTimeURL,
             Connector.READ, true);

        is = socket.openInputStream();
      }
      catch (Exception e) {
      }

      try {
        int b;
        StringBuffer sb = new StringBuffer();
        while ( (b = is.read()) != -1) {
          sb.append((char)b);
        }
        socket.close();
        dt.setText(sb.toString());
        display.setCurrent(outputForm);
      }
      catch (Exception e) {
      }
    }
  }
}

你需要在jad文件中定义两个属性值,当然你也可以直接写在源代码中
DAYTIME_PORT: 13
HOST: 127.0.0.1

本文关键:开发J2ME低级联网应用
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top