Shows the values of the system properties : System Properties « J2ME « Java






Shows the values of the system properties

Shows the values of the system properties

/*
 * @(#)MIDletProps.java 1.0 00/07/18
 * Copyright (c) 1999,2000 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */

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 StringBuffer( 50 );
       props = new Form( "System Properties" );
    
       props.append( "Free Memory = " + free + "\n" );
       props.append( "Total Memory = " + total + "\n" );
    
       props.append( showProp( "microedition.configuration" ) );
       props.append( showProp( "microedition.platform" ) );
       props.append( showProp( "microedition.locale" ) );
       props.append( showProp( "microedition.encoding" ) );
       props.append( showProp( "microedition.encodingClass" ) );
       props.append( showProp( "microedition.http_proxy" ) );
    
       props.addCommand( exitCommand );
       props.setCommandListener( this );
       
       display.setCurrent( props );

    }

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


    /**
     * Show a property.
     */
   String showProp( String prop ) 
   {
      String value = System.getProperty( prop );
      propbuf.setLength( 0 );
      propbuf.append( prop );
      propbuf.append( " = " );
      if (value == null) 
      {
         propbuf.append( "<undefined>" );
      } 
      else 
      {
          propbuf.append( "\"" );
          propbuf.append( value );
          propbuf.append( "\"" );
      }
      propbuf.append( "\n" );
      return propbuf.toString();
    }


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

    /**
     * No op
     */
    public void destroyApp( boolean unconditional ) 
    {
       System.out.println( "In destroyApp" );

    }

}


           
       








Related examples in the same category