Mobile Phone Development

Colin P. Fahey


<<< BACK TO MOBILE DEVELOPMENT


REALISTIC COMPLEX APPLICATION

INTRODUCTION

The simple application presented in the sections above only has a single source code file, and the application does so little that it hardly serves as an illustration of actual cell phone programming. My close friend Sam Robertson wrote an interesting application in J2ME that trains you to play the card game "Blackjack". You are presented with a dealer card, and your pair of cards, and you must decide what to do: Stay, Hit, Double-Down, or Split. This application has six source code files. The application responds to user input, and does simple drawing and text updates. By the way, I totally changed Sam's source code to my own wacky coding style, so don't blame Sam if you think the name conventions, braces, and indenting is insane!

SOURCE CODE

Click on the following link to get the source code, *.JAD file, manifest.mf file, and a batch file, all in one convenient ZIP file. Source Code ZIP File (sbj.zip) Extract to an arbitrary directory, but if you extract to "c:\" under Windows, the following example discussion will be even closer to your actual situation.
FIGURE: sbj.zip extracted to "c:\" (i.e., creates "c:\sbj" directory).

MANIFEST FILE

FILE: manifest.mf

MIDlet-1: My_Description,, SBJ_MidletT MIDlet-Name: SBJ_MidletT MIDlet-Vendor: Sam Robertson MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0

BATCH FILE TO BUILD APPLICATION

The following batch file is crude, but it serves as an illustration of how you might get started with writing your own batch file to build your J2ME application. This example batch file does the following: (1) Delete directory containing old *.class files; (2) Delete directory containing old VERIFIED *.class files; (3) Make a "classes" output directory; (4) Compile all *.java sources in to *.class files, with output going to the "classes" directory. (5) Make a "verified" output directory; (6) Preverify all classes in the "classes" directory, and place verified classes in the "verified" directory. (7) Create a JAR file, and add the mainfest file, and all classes in the "verified" directory; *(8) Test app via preverified classes directly; *(9) Test app via JAR and JAD files; (*...These steps are commented out in my batch file.) FIGURE: File "build_sbj.bat" to build application. Here is the same file in plain-text format for convenient cut-and-paste: FILE: build_sbj.bat

rmdir /S /Q classes rmdir /S /Q verified del /F /Q *.jar mkdir classes javac -g:none -target 1.1 -d .\classes -bootclasspath c:\j2me\midp\classes *.java mkdir verified preverify -classpath c:\j2me\midp\classes;.\classes -d .\verified .\classes jar cvfm sbj.jar manifest.mf -C .\verified . REM midp -classpath c:\j2me\midp\classes;.\verified SBJ_MidletT REM midp -classpath c:\j2me\midp\classes;.\sbj.jar -descriptor sbj.jad REM Finished

BUILDING FROM THE COMMAND LINE

Here is the result of running the "build_sbj.bat" batch file at the command line:
FIGURE: Running the "build_sbj.bat" batch file. Note that the warning messages for the "rmdir" and "del" operations simply indicate that there is nothing to remove. You can see the new directories ("classes" and "verified") and the new *.JAR file that resulted from running the batch file:
FIGURE: Source files and new generated files.

JAD FILE

In order to deploy the sbj.jar file, we need to create and edit the sbj.jad file to have the correct JAR size in the appropriate field: FILE: sbj.jad

MIDlet-1: SBJ_MidletT, , SBJ_MidletT MIDlet-Jar-Size: 7257 MIDlet-Jar-URL: sbj.jar MIDlet-Name: Sam Blackjack Trainer MIDlet-Vendor: Sam Robertson MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0

You may have to add the complete URL to the *.JAR file when you put the *.JAD on your WWW site -- but I discovered (by an experiment) that I was able to get away with not mentioning the full URL (i.e., I just had the JAR filename by itself). You should probably put in the complete URL, but I wanted to let you know what I observed.

SUMMARY

Having multiple source files in your project is common, and in this section we gave a crude illustration of building multiple classes, followed by packaging and execution. Please see the following section regarding using Sun's Wireless Toolkit, which makes building applications much easier.


<<< BACK TO MOBILE DEVELOPMENT



CONTACT INFORMATION

Colin P. Fahey cpfahey@earthlink.net

http://www.colinfahey.com