Creating your first LWUIT MIDlet using the default theme

This topic aims to help you create your first LWUIT MIDlet using the default Nokia theme. The following list of steps demonstrate how to create a simple HelloWorld MIDlet that displays the Hello World label using the default theme.

Assumption

This guide assumes that you are already using Nokia Asha SDK 1.2 or older. If not refer to, Nokia Asha overview page

Steps

  1. From the Start menu, select Nokia Asha SDK > Nokia IDE for Java ME (Eclipse) v3.1. The Workspace Launcher dialog appears.

    Figure 1. Selecting the workspace

  2. Click OK to use the default workspace. This launches Nokia IDE for Java ME (Eclipse).

  3. Create a new MIDlet project by selecting File > New > MIDlet Project. The New MIDlet project window appears.

  4. Specify HelloWorldDefaultTheme in the Project name field and click Finish.

    Figure 2. Creating a MIDlet project

    The newly created MIDlet project appears on Nokia IDE for Java ME (Eclipse).

    Figure 3. HelloWorldDefaultTheme MIDlet project on Nokia IDE for Java ME (Eclipse) v3.1

  5. Right-click on the MIDlet project and select Properties. The Properties dialog for the MIDlet project appears.

  6. In the Properties dialog, click Java Build Path and select the Libraries tab.

  7. Click Add External Jars and add the LWUIT for Nokia library package from this path: <Nokia Asha SDK 1.2 Install Path\Devices\Nokia_Asha_SDK_1_2\plugins\lwuit\lib\asha-sdk\asha-with-theme.jar>. This package contains the LWUIT libraries required for running this MIDlet project.

    Figure 4. Adding LWUIT for Nokia library package from the Libraries tab

  8. Ensure that asha-with-theme.jar is selected in the Order and Export tab and click OK.

    Figure 5. Selecting LWUIT for Nokia library package from the Order and Export tab

  9. In the Package Explorer view, right-click on HelloWorldDefaultTheme > src and select New > Java ME MIDlet. The New Java ME MIDlet window appears.

    Figure 6. Creating a Java ME MIDlet

  10. Specify the following details in the New Java ME MIDlet window and click Finish:

    • Package: A package name for your Java ME MIDlet, for example, com.example.helloworld.

    • Name: A name for your Java ME MIDlet, for example, HelloWorldMIDlet.

    Figure 7. Specifying the Java ME MIDlet details

    The HelloWorldMIDlet.java is loaded into the workspace.

    Figure 8. HelloWorldMIDlet.java is loaded into the workspace

  11. Add the following import statements after import javax.microedition.midlet.MIDletStateChangeException; in HelloWorldMIDlet.java and save your changes. This includes the LWUIT libraries required for this MIDlet.

    import com.sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Label;

    Figure 9. Adding LWUIT import statements

  12. Add the implementation (following code) for the startApp() method in HelloWorldMIDlet.java and save your changes. This implementation displays a Hello World label, based on the default LWUIT theme.

    	protected void startApp() throws MIDletStateChangeException {
    		/* Display.init() method must be first called to initialize LWUIT */
    		Display.init(this);
    		
    		/* Create an instance of Form */
    		Form form = new Form();
    		
    		/* Create an instance of Label */ 
    		Label label = new Label("Hello World!!!");		
    		
    		/* Add label on form */
    		form.addComponent(label);
    		
    		/* Show the form */
    		form.show();
    
    	}

    Figure 10. Updated startApp() method

    Figure 11. Complete HelloWorldMidlet.java source code

  13. Run the MIDlet project by right-clicking on the project and selecting Run As > Emulated Java ME MIDlet.

    Figure 12. Running the MIDlet project

    The MIDlet project output is displayed on the emulator as follows.

    Figure 13. HelloWorld output

Next steps


Last updated 5 March 2014

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×