home
home profile hosting info news fun stuff Technical Stuff support contact us
J2ME STOPWATCH APPLICATION

J2ME StopWatch Application

This application is currently at version 1.1.0 -- last update 14/Aug/2006.

A couple of years ago when I got my Nokia 6600 mobile, I was initially over the moon with the facilities the phone was offerring and also the fact that it was programmable in Java (J2ME). Like all the other enthusiasts (read geeks :D) of the J2ME platform I found myself soon writing all sorts of useless mobile applications that I would then try on my mobile. Soon though I discovered that my mobile was missing one utility that I did occasionally need -- a stopwatch! So having realised that, I started writing this application which I still use on my Nokia from time to time.
I heard that the new models (Nokia N-series) do actually include such a tool, but I cannot confirm it yet as in the meanwhile I switched to a Sony Ericsson mobile and kind of postponed the idea of trying the N-series Nokia's for later on. (As you probably are aware, the Sony Ericsson mobiles have such a stopwatch utility builtin.) Even if they do have such an utility, you might still want a stopwatch that's customizable (see below) or maybe you just want an alternative to the standard ones -- either way, feel free to use (and adapt) this application to your liking.

Note for the impatient users: Click here to scroll down to the download link.

For the not-so-impatient ones, there are a couple of things you might want to know before downloading the application and starting to customize it:

  • First and foremost, the application has been compiled using Wireless Toolkit 2.1 and uses CLDC-1.1 and MIDP-2.0 profiles. If you are going to target a more recent phone you could change this and compile it specifically for your platform.
  • Also note that due to the fact that it targets MIDP-2.0, if planning to deploy this on an older phone (for instance, one that only supports MIDP-1.0), the application will not work out-of-the-box. It is likely that you can adapt the code to work on this platform but I am not willing to provide such backward compatibility as most of the phones that I have encountered in the last couple of years support MIDP-2.0.
  • I have tried this application on a Nokia 6600 series and on Sony Ericsson 750i and W900i and it worked fine. Due to the fact that it doesn't use any Nokia or Sony Ericsson specific libraries/calls/etc, it should work fine on all the other devices that support J2ME. However, if you find it to have problems running on your phone, please let me know by using the Support Page. Please make sure that you select Report Mobile Application Problem from the dropdown menu when sending such a message.
  • If you think the application is lacking certain facilities (quite likely) and/or you have extended it to include such facilities, please feel free again to use the Support Page to send me a message and I will get back to you and find a way to incorporate such changes in the application.

Installing the Application

There are a few ways you can install this application on your phone. I would strongly recommend that you download the jar file and then install it to your mobile via Bluetooth, as the cost is zero doing it this way, however, feel free to use over-the-air installation as well, but be aware that your network operator might charge you for the transfer.

  • Installing via Bluetooth -- If your mobile supports Bluetooth connections and if you have a way to connect your computer to your mobile via Bluetooth (e.g. a Bluetooth USB dongle), then you can use this method. The advantage of this method is that there is that there will be no charge on your mobile for installing the application. Simply download the application binaries, which are packaged in a jar file, to your computer. (To download the binaries, go to the downloads section at the bottom of the page.) Save the file on your hard disk as j2me_stopwatch.jar. After the file has finished downloading, using your Bluetooth software tools (normally these come with either the USB Bluetooth dongle, the operating system or with the phone) copy this jar file onto your phone. At this step your mobile phone will prompt you whether you want to install this application or not. Simply accept the installation and allow for the software to be installed. Once installed, the stopwatch application will be stored on your phone and you can use it any time you want.
    Please note that certain phones might take you through a few confirmation steps during the installation process. Such steps are not described here and you should consult your mobile phone manual for this. Also note that certain mobiles that have a memory card/stick/etc will probably prompt you whether you want the application to be saved onto your mobile memory or the memory card/stick. It is irrelevant from the application's point of view where you install it and the application will work the same whether saved onto your mobile memory or on the memory card.
  • Over-the-air Installation -- If you do not have Bluetooth support in your mobile (unlikely!) or you do not have a way to connect your PC to your mobile via Bluetooth, and you have internet access on your mobile phone, you can use this method to install the application. Be aware that this method involves accessing the internet from your mobile phone and your network operator will more than likely charge you for that. However, if you have a certain download limit included in your contract, or the cost of such download is rather negligeable, than you can proceed using this method. To use over-the-air installation, using your mobile, navigate to the link (provided below) to download the application descriptor. The application descriptor is a file in a certain format that "describes" the application to the mobile, in order to allow the user to see certain details and make up his/her mind whether s/he should continue with installing the application. This descriptor file also contains the URL where the actual application binaries (the jar file) can be downloaded from, should the user chose to continue with the installation. So when entering the link in your mobile and navigating to it, your mobile phone will download this file and it will prompt you with details about the application and whether you want to continue with the installation. If you decide that you want to continue, then the mobile phone will download the jar file that contains the application and then take you through all the confirmation screens necessary when installing a Java application.
    Please note that the size of the jar file is about 19K, so the download shouldn't take that long -- but then again, this depends on your connection speed.
    To download the application descriptor the link is: http://www.liviutudor.com/tech/downloads/j2me_stopwatch.jad (note that this link is also given below in the Downloads section.)

Compiling the Application

If you decide that you want to modify the application, you will need to download the sources. These are provided in the Downloads section below, packaged in a zip file that contains the whole application project. I personally use Eclipse (link will open in a new window) and EclipseME (link will open in a new window) plugin to edit the file and compile them. Obviously, these still rely on the presence of Sun's Wireless Toolkit (WTK) (link will open in a new window) so you will need to have this installed as well. (As stated above, this project relies on WTK 1.1 and above, so if you have WTK 2.0 or a more recent version, that will work just as well.) Due to my using Eclipse, the project included in the zip file is an Eclipse project, however, I am sure it's easy to create a project file for any other IDE that uses WTK.
To edit/change/compile the application simply download the zip file provided below, then unzip it in a folder (keeping the directory structure) and then point Eclipse to that directory when creating a new project in Eclipse. Building the sources should be done automatically every time you change the file (well, at least that's the way I've set up my Eclipse instance). Once you are happy with your application, simply right-click on the project itself in Eclipse and select J2ME --> Create Package -- this will create a jar and a jad file in the deployed directory which then you can upload on your mobile.
Important note regarding compiling the sources: Please make sure that when you compile the sources, the .class files are generating using compliance level 1.1, as J2ME is still JDK 1.1 compatible! Setting your compliance level to a higher value (e.g. 1.5) will create code that your mobile cannot run.

Customizing the Application

The first thing that you will notice (starting with version 1.1.0) is that now there is a Settings dialog which allows you some basic customization -- as it stands at the moment this only offer you switching in between images and built-in fonts when showing the stopwatch digits.

The applications offers a "skinnable" GUI so you can customize it to your liking. This means that you can change the appearance of the digits so they either match your mobile skin or they fit better on your mobile screen.
Please note that the default graphics provided with the application span for exactly 180 pixels in width and 46 pixels in height and this occupies most of the application screen for a Nokia 6600 series phone; however, for other mobiles it might be either too much (in which case you might not see all of the digits) or too little (in which case you might want to increase the size of the images).
In order to customize the application, you will have to download the project file (provided below in the Downloads section. Also make sure that you have WTK (at least) and (even better) Eclipse and EclipseME -- as you will have to re-build the jar file after replacing the graphics. Links for downloading these tools can be found above, in the Compiling the Application section.
Also be aware that if you want to customize the application, you might need some technical knowledge, about how to zip/jar/pack files and also how to create graphics to match your mobile skin. Details on how to do so are not provided here, but there are no doubt loads of reference points on the net. Once you get yourself acquianted to this, you can visit this page again and follow the instructions provided below.
So, if you decide you want to customize the application, here's how:

  • The application uses images to "draw" the digits. These images are stored in the res/img/ directory. They are in PNG format, for portability reasons. (As you are probably aware, the PNG format is the recommended format by J2ME, even though most phones also support GIF and JPEG). Feel free to change the images to JPEG for instance, but be aware that doing so means you will also have to change the sources, as the source code assumes that images are in PNG format.
    In brief, each digit has a corresponding image, the naming convention for the files being digit.png -- e.g. 0.png for 0, 1.png for 1 etc).
  • The simplest customization one can do is to simply remove all the files in this directory or even remove the whole directory. In such case, when the application starts, it will check for the presence of res/img/0.png, if this is not found, then the application will assume that the digit images are not in place and switch to using the mobile fonts for "drawing" the digits on the screen. This is in fact the most portable solution -- as the fonts are quite small and it is nearly guaranteed that all the digits will always be seen on any screen. However, it looks rather lame -- if you ask me :)
  • Another way to customize the application is obviously to replace the images in the res/img/ directory with your own. A few things you need to bear in mind though:
  1. The format of the time shown is HH:MM:SS:mmm where HH is the number of hours, MM is the number of minutes, SS is the number of seconds and mmm is the number of milliseconds.
  2. On top of the images for the digits (0.png to 9.png) there are 2 more images provided: dot.png and semi.png. semi.png is a semicolon (:) and it is used to separate hours from minutes and minutes from seconds; the dot.png file is a dot (.) and it is used to separate seconds from milliseconds.
  3. All the images have to be the same size (width x height) -- this also includes the dot.png and semi.png.
  4. (see comments above) Due to the fact that the number of characters shown is 12, make sure that the width of the images is such that they will all fit on your mobile screen. In other words, make sure that 12 x width of an image <= width of your mobile phone screen.
  • Once you have replaced/delete the images, you will have to re-deploy your application (i.e. re-create the jar file). Details on how to do so are given in the above section Compiling the Application. Then simply re-install the application on your mobile (see the section above Installing the Application for details on how to do so.)

Advanced Customization

On top of replacing the images and "skinning" the application, there are a few other customizations one can make. However, be aware that in order to do this you need to change the source code -- and therefore you will have to recompile and re-deploy the application. It is beyond the scope of this document to provide details on how to go about doing so, however, there are loads of tutorials on Eclipse and EclipseME websites.

  • Change the background color -- By default, the background color for the application is white, however, you can change it to suit your needs by modifying the StopWatchDisplayable.paint() function. Simply locate the lines that calls Graphics.setColor() before drawing a rectangle (that basically erases the whole screen) and replace COLOR_WHITE with the color you want.
  • Change the digits color -- By default, if you decide to go with the non-graphical look-and-feel and have deleted all the images from res/img/, the color used when "drawing" the digits is navy, however, you can change it to suit your needs by modifying the StopWatchDisplayable.paint() function. Simply locate the lines that calls Graphics.setColor() before drawing the digits and replace COLOR_NAVY with the color you want.
  • Change the font used for digits -- If you decide to go with the non-graphical look-and-feel and have removed all the image files from res/img/ then you can change the font used to "draw" the digits on the screen. Simply look in the constructor of StopWatchDisplayable for the line that initializes the fnt member -- this is the font used to "draw" the digits when no images are found. By default, the font is initialized as monospace bold large -- so feel free to change either the font type, the weight or the size.
    Note that there is another font used in the application (fntLaps) however, that is used when "drawing" the number of laps (see below) -- please do not confuse the 2 of them.
  • Change the font used for number of laps -- If you are using the Laps facility in the application, you will notice that the number of laps is shown on the screen using a monospace medium-height font. If you want to change that, simply look in the constructor of StopWatchDisplayable for the line that initializes the fntLaps member.

History

The current version of this application is 1.1.0 and as it stands at the moment I am not tracking previous versions to that. It's very likely that if I decide to maintain this project in the future I will only keep the latest version, however, if at some point I will provide downloads for previous versions as well then the Downloads section below will contain links to all the previous versions of the project.

  • Version 1.1.0 (released on 14/Aug/2006) added a Settings form which allows users at runtime to switch in between graphical digits (i.e. images) and digits "painted" using the device built-in fonts. This came as a request from one of the users who has found the application impossible to use on an LG phone due to the size of the image files. I have then come to realize that not all people downloading this will necessary be interested in re-compiling the application so I have provided the possibility of changing the appearance of the application on-the-fly.

Download the application (jar).
Download the application descriptor (jad) -- please note that this usually will also kick off the process of downloading the actual application if you access this link from your mobile.
Download the application project (binaries and source code).
Read our download disclaimer.


Note that this application is also hosted on getjar.com, so if you prefer you can download it from there, by using this link (link will open in a new window).

Go back to the J2ME page.

Go back to the Technical page.

Go back to the main page.

Home | Profile | Hosting | Info | News | Fun Stuff | Tech | Support | Contact Us | J2ME tips and news

© Copyright liviutudor.com.
Based on a template from TemplatesBox.com

Valid CSS! Valid XHTML 1.0 Transitional Get FireFox! Powered by Debian Linux Powered by Apache Web Server No Software Patents View My profile on LinkedIn

Interesting site about getting Londoners chatting during their daily commute I Can Talk, Me!
Liviu Tudor's mobile applications download free J2ME mobile applications download the source code for J2ME mobile applications J2ME mobile applications for Sony Ericsson and Nokia phones technical tips programming Java java j2me mobile knowledge base request a J2ME mobile application