Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

J2ME - System Properties (See related posts)

// System Properties J2ME

   1  
   2  package System;
   3  
   4  import javax.microedition.lcdui.Alert;
   5  import javax.microedition.lcdui.AlertType;
   6  import javax.microedition.lcdui.Command;
   7  import javax.microedition.lcdui.CommandListener;
   8  import javax.microedition.lcdui.Display;
   9  import javax.microedition.lcdui.Displayable;
  10  import javax.microedition.lcdui.Form;
  11  import javax.microedition.midlet.MIDlet;
  12  import javax.microedition.midlet.MIDletStateChangeException;
  13  
  14  public class SystemProperties extends MIDlet implements CommandListener
  15  {
  16  	private Command esci;
  17  	
  18  	private Display display;
  19  	
  20  	private Form form;
  21  	
  22  	protected void startApp() throws MIDletStateChangeException
  23  	{
  24  		display = Display.getDisplay(this);
  25  		
  26  		form = new Form("System Propiertis");
  27  		form.setCommandListener(this);
  28  		
  29  		esci = new Command("Esci", Command.EXIT, 0);
  30  		form.addCommand(esci);
  31  		
  32  		Runtime rt = Runtime.getRuntime();
  33  		rt.gc(); // Garbage Collection
  34  		
  35  		form.append("Free Memory: " + rt.freeMemory() + "\n");
  36  		form.append("Total Memory: " + rt.totalMemory() + "\n");
  37  		form.append(showProp("microedition.configuration"));
  38  		form.append(showProp("microedition.platform"));
  39  		form.append(showProp("microedition.locale"));
  40  		form.append(showProp("microedition.encoding"));
  41  		form.append(showProp("microedition.encodingClass"));
  42  		form.append(showProp("microedition.http_proxy"));
  43  		
  44  		display.setCurrent(form);
  45  	}
  46  
  47  	protected void pauseApp()
  48  	{
  49  
  50  	}
  51  
  52  	protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
  53  	{
  54  		notifyDestroyed();
  55  	}
  56  
  57  	public String showProp(String str)
  58  	{
  59  		String value = System.getProperty(str);
  60  		StringBuffer stringbuffer = new StringBuffer(50);
  61  		
  62  		stringbuffer.setLength(0);
  63  		stringbuffer.append(str);
  64  		stringbuffer.append(" = ");
  65  		
  66  		if(value == null)
  67  			stringbuffer.append("<undefined>");
  68  		else
  69  		{
  70  			stringbuffer.append("\"");
  71  			stringbuffer.append(value);
  72  			stringbuffer.append("\"");
  73  		}
  74  		
  75  		stringbuffer.append("\n");
  76  		
  77  		return stringbuffer.toString();
  78  	}
  79  	
  80  	public void commandAction(Command c, Displayable d)
  81  	{
  82  		if(c == esci)
  83  		{
  84  			try
  85  			{
  86  				destroyApp(true);
  87  			}
  88  			catch(MIDletStateChangeException e)
  89  			{
  90  				showException(e);
  91  			}
  92  		}
  93  	}
  94  	
  95  	public void showException(Exception e)
  96  	{
  97  		Alert alert = new Alert("Errore !!!");
  98  		alert.setString(e.getMessage());
  99  		alert.setType(AlertType.ERROR);
 100  		alert.setTimeout(Alert.FOREVER);
 101  		
 102  		display.setCurrent(alert);
 103  	}
 104  }

You need to create an account or log in to post comments to this site.


Click here to browse all 5338 code snippets

Related Posts