|
Java ME - NetBeans - Getting Started with Mobile Development

(this tutorial covers NetBeans 5.x; the VMD looks quite different in 6.x, yet
most advice also applies to the latest version)
NetBeans is a very powerful IDE, and is in my opinion well in line with Eclipse (the currently most popular IDE for Java development) by now. Directly when I started developing mobile applications in Java I went for NetBeans. It's a very stable IDE. I haven't encountered one single crash of the tool itself. There are some minor issues
with Visual Mobile Designer, but those issues are at least known and will be fixed in 6.0.This tutorial goes through the first wobbly steps to
create a new project for a mobile application. I give a few pointers so you don't make any obvious beginner's mistakes.

- This is what's shown right after starting NetBeans.
- Close the Welcome panel by clicking on the cross mark on the tab.

- Select File / New Project.
- Select Mobile and Mobile Application in the displayed lists, as shown above.
- Click Next.

- Give your project a name at Project Name.
- Choose a suitable place for the project. Don't use the default setting of somewhere under 'C:\Documents and Settings\...'. That's no good place for your projects. Create a dedicated directory
for all your projects.
- Uncheck Create Hello MIDlet. You don't want that one, ever.
- Click Next.

- Choose what mobile phone emulator to use. I recommend you to use the latest available that's not in beta.
- Choose a suitable Device. DefaultColorPhone has a 320 by 240 display, which is not altogether realistic. You can therefor instead choose MediaControlSkin (176 by 220, if I remember correctly).
All skins look awful, but I guess the Wireless Toolkit team had other things to worry about.
- Choose the lowest configuration and profile your application can accept. By choosing CLDC-1.0 and MIDP-1.0 the likelihood that the application will run as-is on many phones increases a lot, but you'll
sacrifice some functionality. If you had chosen CLDC-1.1 you'd get floating point calculations. Floating point calculations are not much used, so CLDC-1.0 is typically fine. MIDP-2.0 is a tougher decision as it adds quite relevant
functionality. You can though change this later, so I recommend you to start off with 1.0 for both for a first project.
- Click Next.

- If you will make a project that should build different versions of the code for different types of phones you can now choose what such project configurations you want, but for this tutorial
leave them all unchecked.
- Click Finish.
- Your project is now created.

- This is how the screen should look like after having created a project.
- If you want to get started quickly you can now choose to create a Visual MIDlet, so you can edit the UI components visually.
- Right-click on MyFirstApplication, click on New and then Visual MIDlet.

- For a simple project, call the MIDlet the same as the application in the MIDlet name field. Easier to remember that way.
- Let the automatically selected MIDP version be.
- Click Finish.
- Right after creating a Visual MIDlet you'll see the Flow Design, that currently is pretty barren.
- You drag UI elements from the right-most list.
- You add commands to UI elements the same way, and draw flow lines from commands to other UI elements etc.
- Visual Mobile Designer (VMD) will automatically create Java code that corresponds exactly to what you've drawn in the Flow Design View.
- Always name the UI elements logically. Never use the default names, as they are impossible to remember. It takes some time to do this renaming, but you'll thank me later. I use the following
approach:
- Forms, Lists, Alerts, TextBoxes etc: type followed by name, e.g. formChat
- Form items: type followed by the item's container followed by the name, e.g. textChatLog
- Commands: 'cmd' followed by the command's origin followed by the name, that should be the same as the displayed English short label of the command, e.g. cmdChatSubmit
- Resources should also have descriptive names, like imageSplash, fontSmall, etc.
- If this view gets cluttered you can click on the right-most icon on the tab line (looking like two boxes) to clean up the layout.
- The Screen Design tab is used for editing the contents of individual UI elements. To open it you can double-click on any Screen.
- When dealing with command types I recommend the following:
- Use EXIT type for Application Exit
- Use OK type with a very high priority (low value) for Submit, Send, Save, Next etc commands
- Use BACK type for Back, Cancel, Previous etc commands
- Use SCREEN type and a priority to sort low-priority commands in the menu
- In Lists: Set up a command that will be activated when pressing Select
- Note that different phones prioritize commands differently, but the above gives high priority commands a bigger chance to be mapped to soft keys.

- When you select the Source tab you will see the code that VMD has created.
- The blue lines are controlled by VMD, so you can't edit them directly.
- Between the blue lines you can add your application logic.
There's of course infinitely more to mobile development, but if you've never used NetBeans for this before, the above hopefully gives some useful advice.
Note that even when you just have a UI flow, and haven't yet added any application logic, you are still able to build and run the application. It won't do very much, but at least you should be able
to step through the different screens, perform commands etc.
Good luck with your projects!
|