All posts by ajohnson

J2ME StopWatch UI improvements

At Mindseye they gave us every other Friday off during the summer, so naturally I spent the time programming (it rained today in Boston, couldn’t go outside). I did get some feedback from people who installed and/or used the StopWatch app that I released last week. One of the obvious things was allowing the user to start and stop the stopwatch using what is commonly called the “FIRE” button on a phone. Turns out this is relatively easy to do because I was using the Canvas class to paint the screen. The Canvas class is (according to the documentation) “… a base class for writing applications that need to handle low-level events and to issue graphics calls for drawing to the display.” Low level events include things like key press events, pointer events, and game actions. Anyway, long story short, I added the following code to the StopWatchCanvas class constructor:

fireKey = getKeyCode( FIRE );

and this method:

protected void keyPressed( int keyCode ){
  if( keyCode == fireKey ){
    if (thread.isPaused()) {
      // get the thread out of paused mode
      thread.startWatch();
    } else {
      thread.pauseWatch();
    }
  }
}

The first line uses the getKeyCode(int gameAction) method of the Canvas class to retrieve the int value of the gameAction, which in this case is the static variable “FIRE“, also part of the Canvas class.

The keyPressed() method then listens for any and all key pressed events and calls the appropriate method in my thread class to start or stop the watch depending on what state the watch is currently in.

Couple interesting observations about this:


a) if I used one of the high level UI components to paint characters to the screen (like the Screen, Form, Item, etc. classes), I wouldn’t have been able to listen for key events (let me know if I’m wrong about that J2ME experts), so it was easy to do only because I was extending the Canvas class.

b) the options menu that is built by using Command objects still works ok. This is important because users who don’t have a “FIRE” button on their phone can still use the application.

The other UI improvement was that I added a custom icon for the stopwatch application. Didn’t find alot of documentation about this, but from what I can tell, the image that you specify in the MIDlet-Icon attribute of your jad file, must be a 24 bit 32×32 png file. Anything other than that didn’t show up on my 3650 (although it did in the emulator). The screenshots you’re seeing in this post show the icon.

The most helpful article I’ve read about the low-level MIDP api’s is “Using the MIDP Low-Level User Interface API” by Eric Giguere on wireless.java.sun.com. Take a peek if you haven’t already.

Download version 1.1 of J2ME StopWatch now!

Futurama: Using Java Technology to Build Robots That Can See, Hear Speak, and Move

Fun article on developer.java.sun.com called Futurama: Using Java Technology to Build Robots That Can See, Hear Speak, and Move. It explains how to use the Java speech API to capture speech, the Java Media Framework to capture webcam images, and the open source leJOS environment for controlling Lego Mindstorms robots.

On a semi-related note, if you have an MP3 collection (um… yeah I guess that’s all of you), you should check out the .NET application that Joe just released called LANMP3. Pretty cool stuff.

Windows Tail

[update 10:08pm] I know that tail exists for Windows by using cgywin or some of the other ports. If you view the article you’ll see that this utility isn’t run from the command line and uses VB.NET code, which I thought was a interesting…]

From the artima newsletter: Windows tail: “The UNIX operating system has long had a set of really good text file processing utilities. On of the utilities is a program named tail. What tail does is it displays the bottom of a file and then waits for any new information to be written to the end of that file then it displays that information, scrolling up as it goes along. This is perfect for monitoring log files to watch them actually grow as information is being written to them.

Windows has no such command. Also, in the spirit of Windows, I thought it would only be appropriate to have this command using a GUI user interface instead of the command line user interface employed by the UNIX version.

Enter Windows Tail, or wtail.exe. This is a program written in VB.NET using the Microsoft DOTNET Framework 1.1 which must be installed on your system in order for this program to run.

ScreenTaker

I downloaded and installed ScreenTaker by SymbianWare, a nifty little piece of software that gives you the ability to take screen shots of the applications on your Symbian based phone. If you’re using it on the 3650, you should read the instructions on the website, don’t pay attention to the instructions that come with the application. You should press ‘Pencil key + Menu key’ or ‘Pencil key + *’ to take a screen shot.

The picture above is a screen shot taken of my J2ME stopwatch application. I updated the jar & jad files tonight.. download’em again if it didn’t work for you the first time.