Writing Java for the Palm

Writing Java for the Palm

ava continues to make inroads at all levels of computing. Mostrecently, Java has returned to its roots and found a home in the smalldevices for which it was originally designed. Java 2 Micro Editionand its K Virtual Machine (KVM) allow you to write Java applicationsfor handheld devices, including ones that run Palm Computing’sPalm OS. You can download an early version of the KVM fromhttp://java.sun.com/products/kvm.

The KVM includes a reduced set of APIs from the Java 2 platform’sjava.io, java.lang, java.net, and java.util packages. It alsoincludes a package called com.sun.kjava which includes user interfaceand event handling classes for writing applications. At the moment,it only appears to support the Palm OS.

You can write a Palm application by subclassing com.sun.kjava.Spotlet,which provides callbacks for handling events. The KVM manages theevent loop and forwards events to the Spotlet, which are handled bymethods such as keyDown() and penDown(). A Spotlet first needs toregister its event handlers with the register() method before it isable to receive events. This is very different from the traditionalAWT/Swing event model. In fact, none of your AWT or Swing code willport to the current incarnation of the KVM. You unregister yourevent handlers with unregister().

You can compile your KVM apps for the Palm using your regular Javacompiler, setting the classpath to use the KVM classes. But you’llneed to use the utilities included with the KVM distribution in orderto convert your programs into a format you can download to your Palm.These are the palm.database.MakePalmApp program and thepalm.database.MakePalmDB program. MakePalmApp will convert a Javaprogram into a Palm .prc file that will automatically load the KVMto run the program when invoked on the Palm. MakePalmDB allows you toadd classes to the KVM’s class database so that multiple KVMapplications may share classes.

The code below demonstrates a simple HelloWorld Spotlet which displays some text and an exit button:

/*** * To compile adjust the bootclasspath to point to the KVM classes. *   javac -bootclasspath kvmDR4.1_bin/api/classes.zip HelloWorld.java * To make a .prc file add the KVM tools to your classpath. *   java -classpath kvmDR4.1_bin/tools/classes.zip  *        palm.database.MakePalmApp HelloWorld ***/import com.sun.kjava.*;public class HelloWorld extends Spotlet {  private Button __exitButton;  static final String _HELLO_WORLD = "Hello World!";  static final Graphics _GRAPHICS  = Graphics.getGraphics();  public HelloWorld() {    __exitButton = new Button("Exit", 16, 144);    _GRAPHICS.clearScreen();    paint();  }  public void paint() {    __exitButton.paint();    _GRAPHICS.drawString(_HELLO_WORLD, 48, 72);  }  public static void main(String[] args) {    (new HelloWorld()).register(NO_EVENT_OPTIONS);  }  public void penDown(int x, int y) {    if(__exitButton.pressed(x, y))      System.exit(0);  }}
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes