import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloMidlet extends MIDlet implements CommandListener { // Initialize the Midlet Display variable private Display midletDisplay; // Initialize a variable for the doneCommand private Command doneCommand; public HelloMidlet() { // Retrieve the display from the static display object midletDisplay = Display.getDisplay(this); // Initialize the doneCommand doneCommand = new Command("DONE", Command.SCREEN, 1); } /** * Create the Hello Midlet World TextBox and associate * the exit command and listener. */ public void startApp() { // Create the TextBox containing the "Hello Midlet World!!" message TextBox textBox = new TextBox("Hello Midlet", "Hello Midlet World!!", 256, 0); // Add the done Command to the TextBox textBox.addCommand(doneCommand); // Set the command listener for the textbox to the current midlet textBox.setCommandListener( (CommandListener) this); // Set the current display of the midlet to the textBox screen midletDisplay.setCurrent(textBox); } /** * PauseApp is used to suspend background activities and release * resources on the device when the midlet is not active. */ public void pauseApp() { } /** * DestroyApp is used to stop background activities and release * resources on the device when the midlet is at the end of its * life cycle. */ public void destroyApp(boolean unconditional) { } /* * The commandAction method is implemented by this midlet to * satisfy the CommandListener interface and handle the done action. */ public void commandAction(Command command, Displayable screen) { // If the command is the doneCommand if (command == doneCommand) { // Call the destroyApp method destroyApp(false); // Notify the midlet platform that the midlet has completed notifyDestroyed(); } } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |