12 Replies - 26882 Views - Last Post: 31 March 2010 - 03:07 PM

Week #12 Challenge: Java ME

CHALLENGE:
We'll keep up the mobile theme this month with JavaME. Write a basic App for a Cell Phone or Mobile device using JavaME

You don't need an JavaME device to try this challenge. The SDK comes with an emulator!

JavaME is one of the most widely used Mobile development platforms. Developing JavaME Applications is not very complicated and its one app that you can take with you and show all your friends (like pictures of the kids). Since JavaME development kits come with phone emulators you don't even have to own a mobile device to participate.

IDEAS:

Note Taker

Basic Game

Private Photo Album

Bluetooth File transfer

Bluetooth P2P chat

Bluetooth Head2Head game

Text message client

Twitter client

DIC status updater?

Mass Text app

HOW TO GET STARTED:

: Download and install the Java 6 JDK (note: if you already develop in java you should already have this installed and just need to locate the JDK install directory).

: Download and install the JavaME SDK 3.0 (note: if you do not wish to sign up for a Sun One account you can skip that part but the link is very very tiny )

: (optional) download the SDK for your particular phone -- if you would like an emulator for your particular phone you can see if the manufacture has an JavaME SDK available -- I know Sony Ericsson does. Having the platform specific SDK may enable features specific to that manufacturer or phone. A list of links to various manufactures can be found here under Java ME Development Kits.

The SDK comes with a basic IDE that you can use, it has a number of sample applications and emulators available. If you wish you can start right here in the SDK editor. Simply start the Java ME Platform SDK and choose an example project to open and explore.

If you would like to try using another IDE I can recommend Eclipse Pulsar (link above) which I have been using. I will update this post with a short description of how to get a basic HelloWorld application up and running. Meanwhile I highly suggest playing with the SDK demo applications.

EXAMPLE CODE:

package com.nickdmax.firstme;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
/**
* A basic Java ME MIDP MIDlet. Displays a form with the message "Hello Phone".
* MIDlets must implement three methods: startApp(), pauseApp(), destroyApp().<br>
* startApp() -- called to initialize or resume the application. <br>
* pauseApp() -- called to pause the application. <br>
* destroyApp() -- called when exiting - clean up application resources. <br>
* <br>To make the MIDlet have functionality it helps to respond to commands. To respond
* to commands you can implement the CommandListener interface.
* @author NickDMax @ DreamInCode
*/
public class HelloME extends MIDlet implements CommandListener {
private Command exitCmd; //The exit command...
private Display display; //The phone's display
private Form mainForm; //the main form for the application
/**
* Object Constructor -- initializes the Form and the Commands. You could place this
* stuff in the startApp() method but it only need to happen once to setup the form, so
* there really is no need to do it each time the startApp() method gets called.
*/
public HelloME() {
display = Display.getDisplay(this);
mainForm = new Form("Hello Phone!");
exitCmd = new Command("Exit", Command.EXIT, 1);
mainForm.addCommand(exitCmd);
mainForm.setCommandListener(this);
}
/**
* This is called when the App starts or is resumed after a pause (say a phone call),
* so we need to act according to state -- this simple app only has one state (display form).
*/
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(mainForm);
}
/**
* Called to cleanup the app. Not currently used.
*/
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
//No cleanup needed
}
/**
* Called when the phone needs to interrupt the app. You should save the state of the application
* and restore it in the startApp() method.
*/
protected void pauseApp() {
//Nothing to pause
}
/**
* Responding to commands. In this case there is only 1 command - exit.
*/
public void commandAction(Command c, Displayable d) {
if (c == exitCmd) {
try {
destroyApp(true);
} catch (Exception ignore) { }
notifyDestroyed();
}
}
}

Replies To: Week #12 Challenge: Java ME

Re: Week #12 Challenge: Java ME

Posted 22 March 2010 - 02:26 PM

Getting started with Eclipse Pulsar.

I was going to write a bit of a tutorial (and I guess I will) but I found this tutorial here which seems to do a better job than I would be able to (nice pretty pictures). Part 2 goes over how to import the emulators and start a project.

Re: Week #12 Challenge: Java ME

Posted 22 March 2010 - 03:48 PM

Getting Started With Eclipse Pulsar

Step 1: Download and install a Java JDK (keep track of install location)Step 2: Download and install Java platform SDK's for whatever platforms you need (Keep track of install locations)(I did JavaME SDK, Sony Ericcson SDK, LG SDK)Step 3: Download Eclipse PulsarStep 4: Create a directory where you would like to install Eclipse Pulsar (I did C:\Program Files(x86)\Eclipse Pulsar\ )Step 4a: Extract the contents of the "exlipse" folder from the download archive into the created directory.Step 4b: (windows optional) Create a start menu icon: copy the exlipse.exe and "Paste as shortcut" into the start menu (I am really glossing over how to do this if you need help try asking the the OS/Computer Support forum). Step 5: Start the Eclipse App (may need to tell it where you have Java)Step 5a: Choose a location for your workbench (I choose C:\Dev\Pulsar\ )Step 5b: On the start page choose "go to workbench" (when Eclipse first starts it has a cover page, choose to go strait to the workbench, if you would like to return to the cover page just ask me and I will tell you how).Step 6: Import SDKs:...a: Go to the "Window" menu: Window > Prferences...b: JavaME > Device Management ...c: Click the "import" button on the right...d: Browse to the location of The JavaME SDK (for me: C:\Java_ME_platform_SDK_3.0\ )...e: Click Ok. Then Select All then finish...f: Repeat c-e for all SDKs you have downloaded.Step 7: File > New > MIDLet ProjectStep 7a: Give the project a name (HelloJavaME)Step 7b: in the "Configuration" block, Click on the "Add" buttonStep 7b.i: Give the configuartion a name (I choose: "SEW300")Step 7b.ii: Choose an SDK (For me Sony Ericcson)Step 7b.iii: Choose a Device (for me the SonyEriccson_W300) Step 7b.iiii: Finish
(note if you would like to add a few other configurations it will make it easier for testing how your app will look-feel on other platforms)Step 8: Fill Out the MIDLet Project Properties: Note you must have something in these field for the app to deploy to a phone (at least I needed to for my phone).Step 8a: choose default for all other optionsStep 9: Choose "Finish"
Eclipse may ask you to switch perspectives and just choose OK

Writing the code:

Right click the "src" directory in the left hand navigation panel. Choose "New > Package" and pick a package name (for me: "dic.nickdmax" )

Right click on the new package and choose "New > Java ME MIDlet" and give it a name "HelloJavaMe" then "Finish"

Basic Code example:

package dic.nickdmax;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
/**
* A basic Java ME MIDlet. Displays a form with the message "Hello Phone".
* MIDlets must implement three methods: startApp(), pauseApp(), destroyApp().<br>
* startApp() -- called to initialize or resume the application. <br>
* pauseApp() -- called to pause the application. <br>
* destroyApp() -- called when exiting - clean up application resources. <br>
* <br>To make the MIDlet have functionality it helps to respond to commands. To respond
* to commands you can implement the CommandListener interface.
* @author NickDMax @ DreamInCode
*/
public class HelloJavaME extends MIDlet implements CommandListener {
private Command exitCmd; //The exit command...
private Display display; //The phone's display
private Form mainForm; //the main form for the application
/**
* Object Constructor -- initializes the Form and the Commands. You could place this
* stuff in the startApp() method but it only need to happen once to setup the form, so
* there really is no need to do it each time the startApp() method gets called.
*/
public HelloJavaME() {
display = Display.getDisplay(this);
mainForm = new Form("Hello Phone!");
exitCmd = new Command("Exit", Command.EXIT, 1);
mainForm.addCommand(exitCmd);
mainForm.setCommandListener(this);
}
/**
* This is called when the App starts or is resumed after a pause (say a phone call),
* so we need to act according to state -- this simple app only has one state (display form).
*/
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(mainForm);
}
/**
* Called to cleanup the app. Not currently used.
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO clean up any resources allocated
}
protected void pauseApp() {
// TODO save state of application if paused
}
/**
* Responding to commands. In this case there is only 1 command - exit.
*/
public void commandAction(Command c, Displayable d) {
if (c == exitCmd) {
try {
destroyApp(true);
} catch (Exception ignore) { }
notifyDestroyed();
}
}
}

Re: Week #12 Challenge: Java ME

Posted 22 March 2010 - 05:42 PM

I was interested in doing a bluetooth P2P chat... so I am beginning with this description from the API: Part II: The Java APIs for Bluetooth Wireless Technology. I know what your are thinking... if you are close enough to use bluetooth, why not just talk? Well... I don't have a good answer to that. Another point of view is: Why not just text... well I don't know that either... but I wanted to test out bluetooth and I figured this was an easy example.

There are also some WEB APIs.Web is really expensive on my phone so I didn't really think about it... but maybe someone could do a twitter updater.

To receive an SMS, you will have to send the SMS through a port number and the "client" should be listening for text messages on that port. (I have the code for it but I cannot understand my own code.It's been 2 years since I looked at this).

Re: Week #12 Challenge: Java ME

Posted 31 March 2010 - 12:42 PM

I am very interested in participating in this challenge. Just one question. Do we submit the final result in this forum topic? And if so, do you want just the code output, the resulting midlet, or both?