HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Wireless Web Services with J2ME, by Kyle Gabhart & Jason Gordon
WSJ Vol 02 Issue 01 - pg.48

	


Listing 1

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.*;
import org.kxmlrpc.*;

/**
 * @author Kyle Gabhart
 * @copyright Kyle Gabhart © 2001
 * @version 1.0
 */
public class MyMidlet extends MIDlet
 implements CommandListener {
 private List 			list;
 private Command 		exitCommand;
 private String[] 		menuItems;
 private Display 		display;
 private Alert 			response;
 private XmlRpcClient 	xmlrpc;
 private Vector 		params, xmlArray;

 public MyMidlet() {
 //Initialize the User Interface
 menuItems = new String[] {"Timestamp",
 "Randomizer", "AddressBook"};
 list = new List( "Select a service",
 List.IMPLICIT, menuItems, null );
 exitCommand = new Command( "Exit",
 Command.EXIT, 1 );
 response = new Alert("Service Return",
 null, null, AlertType.INFO);
 response.setTimeout( Alert.FOREVER );

 //Add commands
 list.addCommand( exitCommand );
 list.setCommandListener( this );

 //obtain a reference to the device's UI
 display = Display.getDisplay( this );
 }//end MyMidlet()

 public void startApp() {
 display.setCurrent( list );
 }//end startApp()

 public void pauseApp() {
 }//end pauseApp()


 public void destroyApp( boolean bool ) {
 //clean up
 list = null;
 exitCommand = null;
 display = null;
 }//end destroyApp

 public void commandAction( Command com,
 Displayable dis ) {
 if ( dis == list &&
 com == List.SELECT_COMMAND ) {
 switch( list.getSelectedIndex() ) {
 case 0:
 try {
 xmlrpc = new XmlRpcClient(
 "<a href="http://www.wsjug.org/servlet/XmlRpcServlet" EUDORA=AUTOURL>
http://www.wsjug.org/servlet/XmlRpcServlet"/a>" );
 params = new Vector();
 String serverTime = (String)
xmlrpc.execute( "sysTime.getSystemTime", params );
 response.setString(
 serverTime.toString() );
 display.setCurrent( response );
 }
 catch ( Exception ex ) {
 response.setString( ex.toString() );
 ex.printStackTrace(); // DEBUG
 display.setCurrent( response );
 }//end try/catch
 break;
 case 1:
 case 2:
 response.setString( "Please download
 the full sample code);
 display.setCurrent( response );
 break;
 }//end switch( list.getSelectedIndex() )
 }
 else if ( com == exitCommand ) {
 destroyApp( true );
 notifyDestroyed();
 }//end if( dis == list &&
 com == List.SELECT_COMMAND)
 }//end CommandAction( Command, Displayable )
}//end MyMidlet