Developing a Java ME application In this article we will go through a typical installation of the Micro Edition tools and develop a sample application which can be tested on PC and deployed on a mobile device. We will use the Windows XP/Vista PC as our development platform and write an application using the J2ME tools with CLDC and MIDP. These applications are called MIDlets.
Requirements and Downloads 1. Minimum Hardware Requirements: a. 100 MB HDD space, 128 MB RAM b. 800 MHz Pentium III CPU
2. Software Requirements: a. Microsoft Windows XP or Microsoft Windows Vista (I tested on Vista Ultimate) b. Java 2 Platform, Standard Edition (Java SE SDK), version 1.5.0l URL: http://java.sun.com/ javase/downloads/ index_jdk5.jsp l Download the item named “JDK 5.0 Update 16” c. Sun Java Wireless Toolkit 2.5.2 for CLDC URL: http://java.sun.com/ products/ sjwtoolkit/ download.html l Scroll down for the 'Download' button
Figure 2: WTK Folders
Installation Install the JDK first (the sequence is important) followed by the Wireless Toolkit and you are all set to create your first MIDlet. Your installation (by default) would have created the folders in C:\WTK2.5.2 as shown in Figure 2.
The Toolkit You can start the toolkit from Windows Start Button Programs-> Sun Java Wireless Toolkit 2.5.2 for CLDC->Wireless Toolkit 2.5.2 The WTK Window will come up as shown in Figure 3
Creating a New Project for Hello World MIDlet Click on the 'New Project' button. Now, enter the following details and click on 'Create Project'. Project Name: HelloWorldApp MIDlet Class Name: com.j2me.part1. HelloWorldApp This will bring up the API Selection Window shown in Figure 5. Make the following changes and click OK: Target Platform: JTWI Configurations: CLDC 1.1 Optional: None (deselect Mobile Media API) (Only the relevant part of the window is shown here).
The toolkit will create the project and show messages as in Figure 6. This shows the paths where you have to create the source files.
Your source file path will be different from the one shown in Figure 6.
You have to use the path as shown in your messages. You can mark and select the first path shown (source file path) and copy it using Ctrl+C. This will be required in the next step.
Creating the source file for Hello World Application
Open Notepad and enter the following source code:
package com.j2me.part1;
import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet;
public class HelloWorldApp extends MIDlet {
Alert myAlert;
public HelloWorldApp() { myAlert = new Alert("Alert!"); myAlert.setString("Hello World"); }
public void startApp() { Display.getDisplay(this).setCurrent(myAlert); }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { } }
Save this file as HelloWorldApp.java in the fully qualified source path, which is the path you copied in the previous step plus 'com\j2me\part1'. In my case the path isD:\Users\Sudipto Chanda\j2mewtk\ 2.5.2\apps\ HelloWorldApp\src\com\ j2me\part1
Important: Make sure that you select 'All Files', while saving from Notepad, otherwise, Notepad may append a '.txt' extension. It is a good idea to verify the file name to be HelloWorldApp.java.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.