快速业务通道

用J2ME进行联网 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-17
ay;   Form displayForm;   public CurrencyExchange() {    display = Display.getDisplay(this);    exitCommand =    new Command("Exit", Command.SCREEN, 1);   } // Start the MIDlet by creating the Form and   // associating the exit command and listener.   public void startApp() {   displayForm = new Form("Exchange Rate");   displayForm.addCommand(exitCommand);   displayForm.setCommandListener(this); try {   String result = getViaHttpConnection   ("http://finance.yahoo.com/m5?a=1&s=USD&t=GBP");   displayForm.append(" " + result); } catch (Exception exc) {   exc.printStackTrace(); } display.setCurrent(displayForm);   }   // Pause is a no-op because there is no  background   // activities or record stores to be closed.   public void pauseApp() { }   // Destroy must cleanup everything not handled   // by the garbage collector.   // In this case there is nothing to cleanup.   public void destroyApp(boolean unconditional) { } // Respond to commands. Here we are only implementing // the exit command. In the exit command, cleanup and // notify that the MIDlet has been destroyed.   public void commandAction(   Command c, Displayable s) {    if (c == exitCommand) {    destroyApp(false);    notifyDestroyed();    }   } String parse(String str) {   // Get the time of Currency Exchange and Related information   int timeIndex = str.indexOf("U.S. Markets Closed.");   String retTime = "";   if (timeIndex != -1)   {    retTime = str.substring(timeIndex-34, timeIndex);    retTime += " U.S. Markets Closed ";   }   String retVal = "";   int dec = 0;   int index = str.indexOf("USDGBP");   if (index != -1)    str = str.substring(index, str.length()); if ( (( dec = str.indexOf(".")) != -1) && (!(str.endsWith("."))) && Character.isDigit(str.charAt(dec+1)) ) {   String front = "";   int find = dec-1;   while (Character.isDigit(str.charAt(find)))   {     front += str.charAt(find);     find--;   }   retVal += new StringBuffer(front).reverse().toString();   retVal += ".";   String back = "";   int bind = dec+4;   while (Character.isDigit(str.charAt(bind)))   {    back += str.charAt(bind);    bind--;   }   retVal += new StringBuffer(back).reverse().toString(); } System.out.println(retVal); return "USD/GBP " + retVal + " at " + retTime ; } String getViaHttpConnection(String url) throws IOException {      HttpConnection c = null;      InputStream is = null;      StringBuffer str = new StringBuffer();      try {        c = (HttpConnection)Connector.open(url);        // Get the ContentType        String type = c.getType();        // Getting the InputStream will open the connection        // and read the HTTP headers. They are stored until        // requested.       

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号