Activity 10.4 - Writing a MIDlet

Topic

In this activity you are going to write a MIDlet and then run it (debugging if necessary). The MIDlet that you will use is the HelloWorld MIDlet in Unit 10.

Instructions

  1. In NetBeans choose File|New Project...

    In the New Project wizard select Java ME under Categories: and Mobile Application under Projects:

    Screengrab of NetBeans New Project window Mobile selected

  2. Press Next >.

    Name the project MyHello. NetBeans offers to create a Hello MIDlet for us but we are going to write our own, so make sure Create Hello MIDlet is not ticked./

    Screengrab of NetBeans New Project window Create Hello MIDlet unchecked

  3. Press Finish and a new mobile project will be created.

    Screengrab of NetBeans Projects window

  4. Now we will add a MIDlet to the project. In the Projects window, right-click on the node MyHello and choose New|MIDlet... (not Visual MIDlet).

    In the New File wizard, name the MIDlet and the MIDlet class HelloWorld and enter helloworld as the Package:

    Screengrab of NetBeans New File wizard

  5. Click Finish. A new MIDlet will now be created, with a skeleton implementation.

    Screengrab of NetBeans New MIDlet window

  6. In the HelloWorld.java Edit window enter the code for the HelloWorld MIDlet as given in Unit 10. Select Run Main Project and the MIDlet should run as the examples in Activity 3 did. You can compare your result with the one given in the unit. Note, however, that in this version of the emulator you will not be presented with a launch window - the MIDlet will run automatically.