One more time, from the top!!!

My task for today was to set up my home development environment from scratch.

Obviously this should be nothing for a serious programmer, but the problem is that my Sys Admin is just too nice!!! So I’ve been spoiled — for many tasks I could do for myself, I had a bad habit of saying “Oh, I’ll just ask my Sys Admin to do it.” This includes browsing around the http://java.sun.com/ site to find the right Java SE and Java ME versions to download and install. This is weirdly more confusing than it should be, made worse by the fact that I left my java developer account username and password on my computer at work only, and when I hit “send” on the “forgot your password” page, of course it sent the password to my work email address, which I can’t access here. D’oh! So I had to make another account…

I had to get Java SE installed in order to install the wireless toolkit to develop for Java ME, and annoyingly since our last Linux upgrade, the version of Java SE I’d been using seems to have disappeared — I could only find pre-1.4 versions of the JDK, which aren’t recent enough. But with a little navigation effort, I managed to find myself a JDK 1.5.0-09 and a WTK 2.2 download for my system. The installation was simple enough that I won’t bore you with the details. Just read the “read me” — if you can find it on their site!!! Mwa-ha-ha!!!

Once everything was installed, I launched KToolbar. Writing my book, I’d gotten into the habit of running from the command line, keeping in mind that the documentation will tell me all of the possible environment and preferences options. But there’s also something to be said for having a nice GUI where all of the possibilities are right there in the menus. I would recommend being familiar with both the “for simplicity” (GUI) method and the place to go to look deeper. As I’ve said, the WTK documentation is pretty good, and you can find most of the things you’d like to do there.

So from KToolbar, I selected “create a project” for my “Jump” (Tumbleweed) game, and — as expected — the program created everything I needed exept the source code. 😉

Then I copied all of the source files from my Jump game into the directory that the “create a project” option created. I’ve zipped it into a nice file, so if you have your WTK installed, just unzip this under the WTK’s apps directory, and the Jump project will be there when you choose “open a project.” Then build (under the “project” menu) and run.

Now, exactly as Seapegasus discovered here, you’ll find that the screen is too big, so — since I’ve carefully optimized this game for a particular screen size 😉 — you get an exception.

I could go to the source code of JumpCanvas.java and change the screen size requirements, but it looks like Seapegasus has proposed an interesting exercise where that would be cheating. 😉

How do we change the screen size to emulate (and write a program for) the screen of a smaller device? It’s really not obvious… Wandering through KToolbar’s menus, there are a lot of items you can tweak, but screen size isn’t one of them.

Since I wrote this program, I feel responsible for making the effort to figure out how to get it to run. And it’s a fun opening exercise to get to know the entrails of the WTK’s file-structure. 😉

My first instinct was to go after some familiar configuration files that I have to modify all the time in my daily life: WTK/lib/internal.config, WTK/lib/system.config, and WTK/wtklib/emulator.properties. Just look at them — you’ll see that you can modify a lot of system parameters directly right there, especially dealing with networking and communications. But none of them said anything about screen size…

So digging around some more, I noticed the WTK/wtklib/devices directory had subdirectories for all of the various devices…

So, I made a copy of the whole directory “DefaultColorPhone” naming it “CarolColorPhone” ;-), and renamed the DefaultColorPhone.properties under it to CarolColorPhone.properties. In that file I found “screenPaintableRegion.width” and “screenPaintableRegion.height” and thought “Aha, jackpot!” Looking at the values in JumpCanvas.java, I saw that all I needed to do was change the value of “screenPaintableRegion.height” to 250.

Then I ran KToolbar, and “CarolColofPhone” appeared in the little “Device” drop-down menu, and had the desired screen size. This was a particularly fun exercise, because I did the first thing I guessed to do and it worked!!!  (Well, almost the first thing…)  That usually doesn’t happen — it always seems like in an unfamiliar system it’s a little tweak here and a little tweak there for hours until you zero in on what you need to do.

Of course as always, eliminating one bug makes it run just up to the next bug…

The next thing I got was a java.io.IOException…

This is a familiar enough exception with a new set-up that I should have guessed off the top of my head what the problem was, but I didn’t. So I added an “e.printStackTrace()” in a strategic location and built and ran again. Can you guess what it was? If not, the stack trace should make it pretty obvious!!!

java.io.IOException
    at javax.microedition.lcdui.ImmutableImage.getImageFromStream(+15)
    at javax.microedition.lcdui.ImmutableImage.<init>(+20)
    at javax.microedition.lcdui.Image.createImage(+8)
    at net.frog_parrot.jump.Cowboy.<init>(+6)
    at net.frog_parrot.jump.JumpManager.<init>(+72)
    at net.frog_parrot.jump.JumpCanvas.<init>(+249)
    at net.frog_parrot.jump.Jump.<init>(+75)
    at java.lang.Class.runCustomCode(+0)
    at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
    at com.sun.midp.midlet.Selector.run(+22)

Oops, forgot to copy the image files into the right place where they’ll be included in the game’s jar file!!! D’oh!!

But easy to fix. And now it runs, yay!!!! 😀

Advertisements

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: