We will use a step-by-step approach to learn to work with WTK or the Wireless Toolkit. For installation guidance check the appendices. If you are ready letâ€™s begin (the instruction will be Windows based, but it will be similar for other operating systems) â€“
Run the wireless toolkit. You need to run â€œ/bin/ktoolbar.exeâ€. For me the path is â€œC:\WTK22\bin\ ktoolbar.exeâ€. (Use the correct path for all instructions that follow.) You can go to Start menu, choose programs->j2me wireless toolkit->kToolbar
The window will look like â€“
Create a new project named â€˜HelloGroupâ€™ and MIDlet class name as â€˜HelloMIDletâ€™ clicking on the â€œNew Projectâ€ button â€“
In the settings window that pops up for the new project, choose CLDC 1.1 in configuration. This is not important for this particular project but it will be necessary for LBS applications.
Now take a look at the directory structure of the J2ME project. Notice that a folder named â€˜HelloGroupâ€™ has been created in â€œC:\WTK22\appsâ€. All projects are created in â€˜appsâ€™ folder of WTK. Inside the folder there are four other folders and a properties file.
Get the source code. We will use a simple HelloMIDlet.java program for the purpose. Download the code by clicking here. Do you know where to place the file? Good, you guessed it right! Place it in the â€˜srcâ€™ folder. Donâ€™t worry about the code right now; we will analyze it in the next section.
Compile the code. Come back to the wireless toolkit window. Click the â€œBuildâ€ button to compile the project. Be aware that the build process in WTK is not same as a normal java compilation using javac. More about this later.
Look again at the directory structure of the J2ME project. Notice that new folders have been created. The folders â€˜tmpclassesâ€™ and â€˜tmplibâ€™ are created to store intermediate files during the build process. The final class files are stored in â€˜classesâ€™ folder. The â€˜binâ€™ folder now has two files namely â€˜HelloGroup.jadâ€™ and â€˜MANIFEST.MFâ€™. You can open the files using wordpad or other text editors and find out what is inside. We wonâ€™t bother ourselves too much with these now as they are created and updated by WTK. You can have a better understanding later.
Create a jar file by going to project->package->create package. It will create â€˜HelloGroup.jarâ€™ in the â€˜binâ€™ folder. If you want the application to run on a device, you need to transfer the jar file to that.
Run the application by clicking â€˜Runâ€™ button on the WTK window. Bingo! Your first J2ME application runs. Congrats!
Notice there is a drop-down list below the buttons in the WTK toolbar named â€˜Deviceâ€™ where â€˜DefaultColorPhoneâ€™ is selected by default. You can change this setting to have a look at how your application works in different devices.
So far we didnâ€™t look into the java code itself. We will now proceed to the next part to discuss the structure and functioning of the J2ME application.