Subscribe     RSS   MOBILE   EMAIL  
Subscribe to Workshop! It's fun.
Go ahead, pick a reader:
Add to Google
Add to Yahoo
Add to Bloglines
Add to Rojo
Add to Newsgator
Add to Netvibes
RSS Feed
Feed URL:
http://workshop.nseries.com/feed
Scan this code or type this link in your browser for the mobile RSS feed:
http://workshop.nseries.com/feed
Sign up for Workshop emails!
Categories
Archives
Loading
 
17 Jan 2008
 
Tags
 

big pic

Mobile Processing is a great application that makes writing Java (or, more specifically, J2ME) apps for your N95 simple. Learn how to set up Mobile Processing and write your first application.

Mobile Processing is the mobile development side of the Processing project started by Francis Li in 2005. Both Processing and Mobile Processing are free and open source.

If you are familiar with Java or J2ME already, you’ll be a step ahead. Hopefully, though, this will help you even if you’re just getting your feet wet with either of those languages. And, in fact, this is one of the goals of the Processing programming environments: education. They aim “teach fundamentals of computer programming within a visual context,” as they say on the Processing site. But because Processing is actually Java, it has the power and flexibility to write real-world apps - and it’s powerful.

Let’s install Mobile Processing and get started.

Installing Mobile Processing

There’s not much to be said here. Just visit the download page here (on your computer - not your mobile device) and follow those instructions. Mobile Processing works on all major operating systems. The only trick is that you will need to install the Sun Wireless Toolkit if you’re on a Windows box or the Mpowerplayer SDK if you’re using Mac OS X. And, of course, make sure you’ve got the latest version of Java installed. Follow their instructions.

Now run the app. You’ll see a blank canvas if you’re using it for the first time. Since you’re using an N95, you can use the latest-and-greatest stuff built into J2ME, so view the the “Preferences…” in Mobile Processing and select the “Mobile” tab. Make sure the CLDC version is 1.1 and the MIDP version is 2.0. And you’re set. (CLDC stands for Connected Limited Device Configuration. MIDP stands for mobile information device profile.)

To make sure you’ve got everything installed properly, copy this very basic “Hello World!” code into the main Mobile Processing window:

void draw() {

background(0);

stroke(255);
line(10, 10, 10, 50);
line(10, 30, 30, 30);
line(30, 10, 30, 50);
line(50, 10, 50, 50);

}

Run that by clicking the “play” icon in the upper left. Wait a second and your J2ME “player” should open up (Mpowerplayer, if you’re on a Mac like me). This functions as a virtual mobile device. You’ll do most of your testing on this since it’s easier than deploying the app onto your actual device every time you want to test. If everything went right, you should see a very low-fi image of a white “HI” on a black background. If you didn’t get this, go back and check that everything has been installed properly.

If you did get the “HI”, congrats - you’re ready to start making J2ME apps.

A Better Hello World

Okay. So let’s do a “Hello World” that shows of better how Mobile Processing works. Erase what you had above and paste this into your Mobile Processing window on your computer:

boolean show_hi = false;

void setup() {
softkey(”Hello”);
}

void draw() {
background(0);
if( show_hi ) {
stroke(255);
line(10, 10, 10, 50);
line(10, 30, 30, 30);
line(30, 10, 30, 50);
line(50, 10, 50, 50);
}
}

void softkeyPressed(String label) {
if (label.equals(”Hello”)) {
show_hi = true;
}
}

Save it as “Hello_World” and then run it. It should make one of the “soft key” buttons (those two buttons right at the bottom of the screen) read “Hello”. When you push this, the “HI” from above should show up as white lines on a black background. That’s it.

This shows three things built into Mobile Processing. The “setup” function runs once right when the user first runs the app. The “draw” function loops endlessly, making animation a snap, and also giving you easy access on on-screen elements. The “softkeyPressed” function listens for the user to push one of their soft keys (another function “keyPressed”) listens for them to press any key one their device and responds. Within “draw” you’ll see various built-in drawing functions: background, stroke, line. There are many more of these built in to Mobile Processing which you can learn all about on their reference pages here.

Deploy!

Now let’s get this to your N95.

In Mobile Processing select “Export MIDlet…” from the “File” menu. (A “MIDlet,” by the way, is like an “applet,” but for a MID—a “mobile information device.” It’s a funny little term.) After you select “Export MIDlet…” Mobile Processing should show a window in your operating system with three files in it: “Hello_World.jad”, “Hello_World.jar”, and “Hello_World.java”. Open up “Hello_World.java” in a text editor. This is the actual J2ME code Mobile Processing has created for you. In this example it won’t look too different, though you will see the Processing code import and how your Hello_World code is really extending something called a PMIDlet (”Processing MIDlet”). Let’s not worry about this for now. But be aware of its existence. If you ever want to bring your Mobile Processing code into another programming environment such as Eclipse, this will help you out.

Bluetooth the other two files - “Hello_World.jad” and “Hello_World.jar” - to your N95. The “jad” file is a “Java descriptor.” Open it in a text file, if you’d like. It just has some meta-data about your app such as name, version, size, etc. The “jar” file - “Java archive” - is the app itself. Don’t open this in a text editor - it’ll look like garbage. But do send both to your device. I would recommend putting them in a folder called “Processing” to keep the files on your N95 clean.

Go into the “File Manager” app on your N95. It’s under “Tools.” Browse to where you saved your Hello_World files and launch “Hello_World.jad.” You’ll see an alert like “Preparing Installation” and then it’ll double-check that you want to install this. Yes, you do. (Ignore the security warning; you wrote the app, so you know it’s not going to do anything malicious.) After choosing where to put it, you’ll see a progress bar as the app installs.

When that’s done, go into your Applications folder and scroll down to the bottom. What’s that? Hello_World! Great! Run it. You should see your “Hello” softkey label and when you push that button “HI” should appear in white on a black background.

Did that happen?

If so - congrats! You’ve deployed a mobile application!

Share your own experience with Mobile Processing and any other mobile programming ideas in the comments section.

 
share          
email   share        print   print       
No Comments
 
Enter comment
Name


Email (not displayed publicly)
 
Related Posts
feature mini
How to manage your music with Nokia Music
feature mini
Useful applications for your N96
feature mini
How to use Mobile Web Server: Part 3
 
Workshop Mobile Code
 
Location:         Language: English