Sunday, March 7, 2010

J2ME - What is a MIDlet

MIDlet in simple words is a mobile application for Java enabled mobile phones. MIDlet is an application that runs on MIDP (Mobile Interface Data Profile) compliant devices. Some times, J2ME apps are alternatively called MIDlets because each executable application starts execution from the MIDlet class.

To start your application programming on J2ME, your main application class should extend javax.microedition.midlet which is defined in MIDP. We will see in detail, what is a MIDlet lifecycle but right now I'm listing a simple MIDlet applcication that shows a simple Hello World message.


package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloMIDlet extends MIDlet implements CommandListener {

    private Command exitCommand; // The exit command
    private Display display;     // The display for this MIDlet

    public HelloMIDlet() {
        display = Display.getDisplay(this);
        exitCommand = new Command("Exit", Command.EXIT, 0);
    }

    public void startApp() {
        TextBox t = new TextBox("Hello", "Hello, World!", 256, 0);

        t.addCommand(exitCommand);
        t.setCommandListener(this);

        display.setCurrent(t);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
        if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }

}



If you've been reading the tutorials in sequence, you must have recognized that this is the same code we posted in an earlier post. Read this post to read more about the details of this code and how it works.

This is important to know that unlike other platforms where java runs, J2ME has not main method to start the application. Its rather the startApp() method of the MIDlet class that is called by the runtime to initiate the execution of the application.

To read further, please read "What is a MIDlet lifecycle".


Other related articles:

J2ME - How to write your first app.
J2ME - How to set up development environment on Windows
J2ME - What is a MIDlet life cycle




2 comments:

  1. I read your article and gain knowledge about iPhone Application Development. Thanks for Sharing very informative and valuable information........

    ReplyDelete
  2. We are delighted to work with Youteam on our web development projects. They have provided a team of highly capable engineers which has been a key enabler in our execution. The engineers are smart and detail-oriented.Hiring A Remote Software Engineer.

    ReplyDelete