Monday, December 10, 2012
Memperoleh jumlah memori yang tersedia pada JAVA (J2ME)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class JumlahMemori extends MIDlet
implements CommandListener {
private Display display;
private Form form;
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
public JumlahMemori() {
display = Display.getDisplay(this);
form = new Form("Jumlah Memori");
form.addCommand(cmdKeluar);
form.setCommandListener(this);
}
public void startApp() {
Runtime runtime = Runtime.getRuntime();
runtime.gc();
long total = runtime.totalMemory();
long bebas = runtime.freeMemory();
StringBuffer sb = new StringBuffer();
sb.append("Memori total: " + total + " byte\n");
sb.append("Memori bebas: " + bebas + " byte");
form.append(sb.toString());
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment