Implementing the MIDlet Main class

The Main class is the MIDlet main class. When the MIDlet is launched, the Main class is loaded first.

To implement the Main class:

  1. Create the Main.java class file.

    package com.nokia.example.nnaclientexample;
    
  2. Import the required classes and packages.

    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
  3. Create the Main class to extend the MIDlet.

    The Main class owns the object of the MainView (UI class).

    public class Main extends MIDlet {
        private MainView mainView;
  4. Create the Main class constructor.

    public Main() {
    }
  5. Define the mandatory lifecycle methods for starting, pausing, and destroying the MIDlet.

    public void startApp() {
        mainView = new MainView(this);
        Display.getDisplay(this).setCurrent(mainView);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void quit() {
        destroyApp(true);
        notifyDestroyed();
    }
    }

Now that you have implemented the MIDlet Main class, implement the MIDlet MainView class.