Building a J2ME Application in NetBeans 4.1
This code should make sense if you understood the store code; it is basically a reversal of the store functionality. Strings are re-constructed from the byte arrays, and then parsed into the longs. Finally, the averages and summary update method are invoked, to get everything in sync.
So, now you have methods to save and load the data, but you are not calling them anywhere. You could choose to call the save method whenever the initialize or add details methods are used, and load on startup. I usually choose to put the save methods into the pauseApp and destroyApp lifecycle methods instead:
- Find the startApp() method, and after the initialize(); call, add
- Find the pauseApp() and destroyApp(boolean unconditional) methods and in both add the line:
Getting the App onto a Device
Once you are happy with your application, it's time to get it onto a device. This requires the construction of a jar and jad file for the application. The jar file is the packaged executable, and the jad describes it to the device, so these two normally go in combination.
Fortunately, the NetBeans mobility pack makes it really easy to package up the application into these files. Simply right-click on the MileageCalculator project and select Deploy Project. This seems to give an error about a missing ant property, and I need to look into why this is (update in a later article). However, even in spite of this, the jad and jar files are created in the dist directory of the project home anyway and are ready to deploy to your device, so just pick them up from that directory.
As to actually getting them onto your device, there are numerous ways to do this. One is to put the jad and jar files out on a Web server and then browse to the jad file using WAP on your phone (that is probably the most universal way to do it, assuming you have WAP access on your phone). Alternatively, you may find that your phone or other device came with software, or has software for download, that will let you install the application. For example, the Nokia PC suite, a free download from nokia.com, lets me load applications directly onto my series 40 device.
In this article, you have put together a simple and not particularly pretty mileage calculator that should be able to run on any Java-enabled phone or other device. The application has illustrated the main points of Java ME development apart from online communication (which I hope to cover in a future article). The mileage app might be useful in its current form, but probably would be better if extended and improved.
I hope this demonstrates that Java ME application development is easy, particularly with NetBeans and the Mobility Pack. I also hope this spurs more people to create applications that I can use on my phone. :)
About the Author
Dick Wall is a Lead Systems Engineer for NewEnergy Associates, A Siemens Company based in Atlanta, GA that provides energy IT and consulting solutions for decision support and energy operations. He can be reached for comment on this and other matters at email@example.com. He also co-hosts the JavaCast, a podcast devoted to Java news and the Java community, which can be found at http://javacast.thepostmodern.net.
Page 5 of 5