Building J2ME Application

J2ME stands for Java 2 Micro Edition, a kind of limited Java programming which lives on a Java enabled mobile gadgets such as cell phone. I used to developed these since there were some orders came to me for couple years ago.

To build this such application, you need full packages of J2SDK, the runtime environment J2RE and the J2ME compiler (and also - it will be nice if you are already - familiar with C programming language). My Favorite J2ME compiler is SunOne Studio Mobile Edition. It’s IDE is great and so powerfull to build various Java applications.

click to enlarge
I’d like to show you about a sample how to build an J2ME application. This application called JogjaGuide, a kind of mobile information center which brings you fast seeking about important place on Yogyakarta city you should go in a hurry. Basically, it also need a web server since the application requesting data over http protocol. Just another similar technique equally with SOAP which I’ve been explained 2 days ago. Anyway, let’s see the JogjaGuide UML (universal modeling language) plan below:

The UML Statechart Diagram
click to enlarge

The UML Activity Diagram
click to enlarge

First of all, you have to link the J2ME standard library to support your programming in the code editor. It’s typically uses clause on Delphi or include syntax on C++/PHP.

import javax.microedition.rms.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;

import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

import java.util.*;

Then, you have to define the public class, the variable, the objects, and the form manually. Go find your self the example related to it and match it to your application, since it will used up more than 10 pages if I write it down completely!!!. As the UML picture displayed above, I assumed that you already know the work flow. I am just telling you the core of the connection request from mobile to the server on the internet.

In mobile application, this is what you have to define:

public void coreConnection()
{
HttpConnection conn = null;
InputStream is = null;
OutputStream os = null;
StringBuffer stringBuffer = new StringBuffer();

byte[] receivedData = null;

url = "http://target.script.on.the.internet.complete.with.the.parameters;break;

conn = (HttpConnection)Connector.open(url);
System.out.println("sb = <" + url + ">");

byte[] postData = createPostData();
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("IF-Modified-Since","20 Jan 2001 16:19:14 GMT");
conn.setRequestProperty("User-Agent","Profile/MIDP-2.0 Confirguration/CLDC-1.0");
conn.setRequestProperty("Content-Language", "en-CA");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
os = conn.openOutputStream();
is = conn.openDataInputStream();
int ch;
while ((ch = is.read()) != -1) {
stringBuffer.append((char) ch);
}
// display the result here
}

And the final result is exactly likes the pictures below:



The complete binary and source includes you might find on my other site at http://www.skripsionline.cjb.net or have a contact with me directly.

Sincerelly,

Eko Wahyudiharto
PS: If you've benefit from this blog,
you can support it by making a small contribution.

Enter your email address:

Delivered by FeedBurner

Post a Comment Bookmark and Share

 

  1. Blogger Salisy Jones said,

    Wednesday, March 04, 2009 1:08:00 AM

    mas, minta bantuan bisa gak, buatin program untuk image watermarking pada MMS. jadi habis user load image, ada menu untuk nambah watermark ke image, lalu image yang sudah dikasih watermark di send. pakai metode FFT ya kalau bisa. serius nih, bisa kontak ke email saya, urgent. ntar bisa di rembug lagi deh kalau dah ada respon. thanks.

Post a Comment

Leave comments here...