J2ME与Web Service-KSOAP的快速上手[4]

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

本文简介:

  private void jbInit()
  throws Exception
  {
    // Set up this Displayable
 to listen to command events
    textField1 = new TextField
 ("", "", 15, TextField.ANY);
    this.setCommandListener(this);
    textField1.setLabel
 ("待处理的字符串是:");
    textField1.setConstraints
 (TextField.ANY);
    textField1.setInitialInputMode
 ("Tester");
    setCommandListener(this);
    // add the Exit command
    addCommand(new Command
 ("Exit", Command.EXIT, 1));
    addCommand(new Command
 ("Process", Command.OK, 1));
    this.append(textField1);
  }

  public void commandAction
  (Command command,
  Displayable displayable)
  {

    if (command.getCommandType
 () == Command.EXIT)
 {
      WSClientMIDlet.quitApp();
    }
    else if (command.getCommandType()
 == Command.OK)
 {
      t = new Thread(this);
      t.start();
    }
  }

  public void run()
  {
    String s1 =
 textField1.getString();
    String s2 =
 new StringProcessorStub().process(s1);
    StringItem resultItem =
 new StringItem("处理后的字符串是:", s2);
    this.append(resultItem);
}
}
 

 

2.1.3 StringProcessorStub.java


package com.jagie.j2me.ws;

import org.ksoap.*;
import org.ksoap.transport.HttpTransport;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

  public class StringProcessorStub
  {
    public StringProcessorStub()
 {
  }

  public String process(String name)
  {
    String result = null;
    try
 {

      SoapObject rpc =
   new SoapObject
    ("http://localhost:
 7001/jagiews/services/StringProcess",
 "process");

      rpc.addProperty("name", name);

      HttpTransport ht =
   new HttpTransport
    ("http://localhost:7001/
 jagiews/services/StringProcess",
 "");

      result = (String) ht.call(rpc);

    }
    catch (Exception e) {
      e.printStackTrace();
    }

    return result;

  }
}
 

总结

本文关键:J2ME与Web Service-KSOAP的快速上手
  相关方案
Google
 

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

go top