J2ME : Shows the values of the system properties

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * A MIDlet shows the values of the system properties.
 */
public class MIDletProps extends MIDlet implements CommandListener
{

    private Display display;    // The display for this MIDlet
    private Form props;
    private StringBuffer propbuf;
    private Command exitCommand = new Command(“Exit”, Command.SCREEN, 1);


    /**
    * Construct MIDletProps
    */
    public MIDletProps() {
        display = Display.getDisplay(this);
    }

    /**
     * Show the value of the properties
     */
    public void startApp() {
       Runtime runtime = Runtime.getRuntime();
       runtime.gc();
       long free = runtime.freeMemory();
       long total = runtime.totalMemory();
    
       propbuf = new StringBuffer50 );
       props = new Form“System Properties” );
    
       props.append“Free Memory = ” + free + “\n” );
       props.append“Total Memory = ” + total + “\n” );
    
       props.appendshowProp“microedition.configuration” ) );
       props.appendshowProp“microedition.platform” ) );
       props.appendshowProp“microedition.locale” ) );
       props.appendshowProp“microedition.encoding” ) );
       props.appendshowProp“microedition.encodingClass” ) );
       props.appendshowProp“microedition.http_proxy” ) );
    
       props.addCommandexitCommand );
       props.setCommandListenerthis );
       
       display.setCurrentprops );

    }

    /**
    * Eventhandling code goes into commandAction
    */
    public void commandActionCommand c, Displayable s 
    {
      if c == exitCommand 
      {
         destroyAppfalse );
         notifyDestroyed();
      }  
    }


    /**
     * Show a property.
     */
   String showPropString prop 
   {
      String value = System.getPropertyprop );
      propbuf.setLength);
      propbuf.appendprop );
      propbuf.append” = ” );
      if (value == null
      {
         propbuf.append“<undefined>” );
      
      else 
      {
          propbuf.append“\”” );
          propbuf.appendvalue );
          propbuf.append“\”” );
      }
      propbuf.append“\n” );
      return propbuf.toString();
    }


   /**
    * Time to pause, free any space we don’t need right now.
    */
    public void pauseApp() 
    {
       display.setCurrentnull );
       propbuf = null;
       props = null;
    }

    /**
     * No op
     */
    public void destroyAppboolean unconditional 
    {
       System.out.println“In destroyApp” );

    }

}



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.