J2ME - System Properties


/ Published in: Java
Save to your folder(s)



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.