FileDocCategorySizeDatePackage
PropExample.javaAPI DocJ2ME MIDP 2.02402Thu Nov 07 12:02:16 GMT 2002example

PropExample

public class PropExample extends MIDlet implements CommandListener
An example MIDlet shows the values of the system properties. Refer to the startApp, pauseApp, and destroyApp methods so see how it handles each requested transition.

Fields Summary
private Display
display
private Form
props
private StringBuffer
propbuf
private Command
exitCommand
Constructors Summary
public PropExample()



    /*
     * Construct a new PropExample.
     */
      
	display = Display.getDisplay(this);
    
Methods Summary
public voidcommandAction(Command c, Displayable s)

	if (c == exitCommand) {
	    destroyApp(false);
	    notifyDestroyed();
	}	
    
public voiddestroyApp(boolean unconditional)
Destroy must cleanup everything.

    
public voidpauseApp()
Time to pause, free any space we don't need right now.

	display.setCurrent((Displayable)null);
	propbuf = null;
	props = null;
    
java.lang.StringshowProp(java.lang.String prop)
Show a property.

	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();
    
public voidstartApp()
Show the value of the properties

	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.profiles"));

	props.append(showProp("microedition.platform"));
	props.append(showProp("microedition.locale"));
	props.append(showProp("microedition.encoding"));

	props.addCommand(exitCommand);
	props.setCommandListener(this);
	display.setCurrent(props);