Gidlet
 
 

 

Learning Java with J2ME

Gidlet is the name of a class library based on J2ME (also called Java ME) to develop Java applications that run on handheld wireless devices like mobile phones. It is specially designed for introductory courses in Java programming where it is important to accentuate the principles of the programming language. The library follows the well-known educational pattern to start programming with graphics applications, which gives lot of motivation and fun. Gidlet means Graphics Information Device and the Gidlet class is derivated from the MIDlet (Mobile Information Device) class with some very useful extensions. We say that an application that uses the Gidlet library "is a gidlet".

A gidlet is developed like any other Java program on a computer within your favorite IDE. The source program is edited and compiled using the ordinary J2SE compiler. Because the Java Virtual Machine running on the mobile phone is restricted due to the limited processor resources, the display and the input devices of mobile phones, the Java API distributed with J2ME is much smaller, but the language features remains almost the same. This can be an advantage for beginners who are often overwhelmed by the huge API of J2SE.

The compiled application can be tested without any real mobile phone using a virtual mobile device, called an emulator. Once the program runs on the emulator to your satisfaction it can be downloaded to the real device via a USB or Bluetooth link or deployed on a Web server and made available to the public.

The following code shows an example of a very simple gidlet drawing a Moiré pattern. It could be written without many forward references in the very first lessons on programming. Compare this code with the usual FirstMIDlet applications and you see how simple it is.

// MoireGidlet.java

import
 ch.aplu.gidlet.*;

public 
class MoireGidlet extends Gidlet {
  
public void main()
  
{
    MPanel p 
new MPanel();
    p.
window(0, 5, 0, 5);

    
int i, k;
    
for (i = 0; i <= 5; i++)
      
for (k 0; k <= 5; k++)
        p.
line(i, 0, k, 5);

    
for (i = 0; i <= 5; i++)
      
for (k = 0; k <= 5; k++)
        p.
line(0, i, 5, k);
  
}
}
 
 
Execute MoireGidlet
(if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension)
 

 

The Gidlet Framework

The Gidlet class library is based on two other similar frameworks for C++, called Champ, and the ch.aplu.util/ch.aplu.turtle package under J2SE. The purpose is to provide a tool to develop Java programs in the educational environment, where the learning curve should be kept gentle. Teaching experience in many programming courses in the past twenty years shows that graphics oriented applications, game development and Internet-aware applications give a motivation thrill to tackle the burden of a modern programming language.

Important Features (of Version 1.x):

  • MidPak, a packaging utility that creates the necessary archive (JAR) and application descriptor (JAD) files and runs the emulator
  • MPanel, a class derived from javax.microedition.lcdui.game.GameCanvas to create incremental and animated graphics using a user defined coordinate system (double coordinates)
  • Turtle, a class for direction oriented graphics inspired by the Logo programming language
  • MConsole, a class for writing to a console-like display with common print/println methods
  • MForm, class derived from javax.microedition.lcdui.Form, a display with easy integration of the standard J2ME items
  • Complex, a simple implementation of complex numbers
  • Float11, a extension for basic mathematical functions that are not included in J2ME
  • BluetoothFinder, a class that simplifies the process of detecting Bluetooth devices and their services
  • MFile, a class that simplifies the use of the File Connection Package (JSR 75) to access the local file system
  • NxtJLibMP, a package with a clean OOP design for programming the Lego NXT robot
  • Source code included for free

The user application class extends the Gidlet class which is derived from javax.microedition.midlet.MIDlet and implements the entry point method void main(), that is called in a separate thread when the gidlet is started. A standard Exit soft button is displayed automatically. Clicking the Exit button will terminate the application. This makes the skeleton of a Gidlet extremely simple:

// BasicGidlet.java

import
 ch.aplu.gidlet.*;

public
 class BasicGidlet extends Gidlet
{
  
public void main()
  
{
    ...
    ...
    ...
  
}
}