/* this midlet creates a mutable image, draw text within the image and put it onto a form. Note the precedures of changing Mutable image to immutable because Forms, alerts, choice and Image Items only accept immutable images*/ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; //import java.io.IOException; public class MuteImage extends MIDlet implements CommandListener{ private Display display; // a display private Form fmMain; // main form private Command cmExit; // exit command private static final String mssg = "MIDP Course"; // reference to a message // constructor public MuteImage(){ display = Display.getDisplay(this); // add command cmExit = new Command("Exit", Command.EXIT, 1); // create a muttable image and get graphics object for image Image tmpimg = Image.createImage(90, 30); // determine size Graphics graphic = tmpimg.getGraphics(); // Specify font face (system's font), style and size more about this in // future sessions Font fnt = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_MEDIUM); graphic.setFont(fnt); // position the text at the Centre graphic.drawString(mssg, (tmpimg.getWidth() / 2) - (fnt.stringWidth(mssg) / 2) , 0, Graphics.TOP |Graphics.LEFT); // draw a recangle around the image graphic.drawRect(0, 0, tmpimg.getWidth()-1, tmpimg.getHeight() - 1); //create form, add command and listen for events fmMain = new Form(" "); fmMain.addCommand(cmExit); fmMain.setCommandListener(this); // convert the image to immutable and to the form fmMain.append(Image.createImage(tmpimg)); display.setCurrent(fmMain); } // start app public void startApp(){ display.setCurrent(fmMain); } // pause app public void pauseApp(){ } // destroy app public void destroyApp(boolean unconditional){ } // commandAction method public void commandAction(Command c, Displayable s){ if(c == cmExit){ destroyApp(false); notifyDestroyed(); } } }