Java/J2ME/Environment
Attributes MIDlet
<source lang="java">
import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.rumand; import javax.microedition.lcdui.rumandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; public class AttributesMIDlet extends MIDlet implements CommandListener {
private Display display; protected boolean started; private Command exitCommand; protected void startApp() { if (!started) { display = Display.getDisplay(this); Canvas canvas = new DummyCanvas(); Form form = new Form("Attributes"); exitCommand = new Command("Exit", Command.EXIT, 0); form.addCommand(exitCommand); boolean isColor = display.isColor(); form.append(new StringItem(isColor ? "Colors: " : "Grays: ", String.valueOf(display .numColors()))); form.append(new StringItem("Width: ", String.valueOf(canvas.getWidth()))); form.append(new StringItem("Height: ", String.valueOf(canvas.getHeight()))); form.append(new StringItem("Pointer? ", String.valueOf(canvas.hasPointerEvents()))); form.append(new StringItem("Motion? ", String.valueOf(canvas.hasPointerMotionEvents()))); form.append(new StringItem("Repeat? ", String.valueOf(canvas.hasRepeatEvents()))); form.append(new StringItem("Buffered? ", String.valueOf(canvas.isDoubleBuffered()))); form.setCommandListener(this); display.setCurrent(form); started = true; } } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if (c == exitCommand) { notifyDestroyed(); } }
} class DummyCanvas extends Canvas {
protected void paint(Graphics g) { }
}
</source>
Check Color
<source lang="java">
// jad file /* MIDlet-Name: ColorCheck MIDlet-Version: 1.0 MIDlet-Vendor: MyCompany MIDlet-Jar-URL: ColorCheck.jar MIDlet-1: ColorCheck, ColorCheck.png, ColorCheck MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0 MIDlet-JAR-SIZE: 100
- /
import javax.microedition.lcdui.rumand; import javax.microedition.lcdui.rumandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.TextBox; import javax.microedition.midlet.MIDlet; public class CheckColor extends MIDlet implements CommandListener {
private Display display; private TextBox textbox = new TextBox("Check Colors", "", 17, 0); private Command exit = new Command("Exit", Command.SCREEN, 1); public CheckColor() { display = Display.getDisplay(this); String message = null; if (display.isColor()) { message = "Color display."; } else { message = "No color display"; } textbox.setString(message); textbox.addCommand(exit); textbox.setCommandListener(this); } public void startApp() { display.setCurrent(textbox); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(true); notifyDestroyed(); } }
}
</source>
Show Properties
<source lang="java">
/*--------------------------------------------------
- ShowProperties.java
- Example from the book: Core J2ME Technology
- Copyright John W. Muchow http://www.CoreJ2ME.ru
- You may use/modify for any non-commercial purpose
- -------------------------------------------------*/
import javax.microedition.midlet.*; public class ShowProperties extends MIDlet {
public void startApp() throws MIDletStateChangeException { System.out.println("Vendor: " + getAppProperty("MIDlet-Vendor")); System.out.println("Description: " + getAppProperty("MIDlet-Description")); System.out.println("JadFile Version: " + getAppProperty("JadFile-Version")); System.out.println("MIDlet-Data-Size: " + getAppProperty("MIDlet-Data-Size")); Runtime rtime = Runtime.getRuntime(); System.out.println("Total memory: " + rtime.totalMemory()); System.out.println("Free memory: " + rtime.freeMemory()); } public void pauseApp() { } public void destroyApp(boolean unconditional) { }
}
</source>