The Main
class is the MIDlet main class. When
the MIDlet is launched, the Main
class is loaded
first.
To implement the Main
class:
Create the Main.java class file.
package com.nokia.example.fileselectexample;
Import the required classes and packages.
import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet;
Create the Main
class to extend the MIDlet.
public class Main extends MIDlet {
Create the
required variables and the constructor. Check availability of the
File Select API using System.getProperty
method.
private MainView mainView; private final boolean isAPIAvailable; public Main() { isAPIAvailable = System.getProperty("microedition.io.file.FileConnection.version") != null; }
Define the mandatory lifecycle methods for starting, pausing, and destroying the MIDlet.
public void startApp() { if (isAPIAvailable) { mainView = new MainView("File Select Example", this); Display.getDisplay(this).setCurrent(mainView); } else { String text = getAppProperty("MIDlet-Name") + "\n" + getAppProperty("MIDlet-Vendor") + "\nFile Connection API is not available!"; Alert alert = new Alert(text); Display.getDisplay(this).setCurrent(alert); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { }
Create the method to exit the application.
public void quit() { destroyApp(true); notifyDestroyed(); }