Introduction to solutions for writing Palm OS programs in Java
At present, the fields of programming for Palm OS using Java language are not completely unified, and there are also many differences. Currently, there are several available application interfaces on the market, each application interface provides different access permissions to the current Palm OS application. Perhaps everyone is most familiar with Sun Microsystems, but it is not the only product that can write programs for Palm OS. This part of this article is not a tutorial on writing a Palm program using Java-because each solution we will discuss has its own requirements and worth noting-it is a general introduction to developers. development Tool articles, we will look at this field to find out what tools you should use and what you can get when developing Palm OS applications using Java.
I. Sun solutions: KVM, Configuration, and Profile
KVM is a Kilobyte Virtual Machine (kilobytes of Virtual machines), so it is named because its memory size is measured in kilobytes, rather than the size of megabytes as the Java Virtual Machine requires. Because of such demanding memory requirements, KVM functions are only a subset of the complete JVM. You can find all the information on the kerberoft site, but it is worth noting that it misses reflection, JNI, custom class loaders, and a variable security mechanism.
Sun has developed a plan that provides configuration and profile to meet the needs of device programming. Configuration is an application interface designed to provide a foundation for a wide range of general devices. All these devices have similar features, such as limited memory, due to the occasional strong network connectivity, low power consumption, and running on the battery, the j2s are designed to be both general and abstract. Currently, Java 2 Micro Edition (j2s) supports CLDC (Connected, Limited Device configuration) and CDC (Connected Device Configuration, the latter is used for devices that are more powerful than Palm, which is beyond the scope of our discussion. The former represents the configuration of limited-connection devices, such as PDAs, dual-channel receivers, and mobile phones. CLDC includes a subset of classes in J2SE, but there are some important differences, such as the useless Unit collection mechanism used by virtual machines on small devices, CLDC's java. lang. an Object does not contain the finalize method. You should remember that a specific class in this application interface may appear, but a method does not. Please refer to the application interface document so that you will know when to use the configuration.
It is strange that CLDC does not support floating point numbers. This is the default Implementation of KVM. KVM is written in C and can be transplanted to many platforms. It does not support floating-point operations. This is because the hardware we face is generally small devices, some still use 8-bit processors, which may not support floating point operations.
Profile is special and specific. Its target is a class of devices more specific than configuration, including user interfaces and event processing elements, which does not appear in configuration. Currently, no public profile is available for Palm OS or PDA.
Java Community Process has a PDA Profile that has been developed for a period of time, and developers are still waiting for a new PDA profile version. At the same time, what should developers who want to follow the KVM/Sun solution do? CLDC includes the smallest set of classes that can be used as the original profile of Palm OS. Sun does not agree to use these classes to develop any commercial programs, they do not plan to update this application interface. If you do not have a PDA profile, you can also use these class libraries. What we usually know is Kjava, which contains many GUI classes: CheckBox, RadioButton, List, and so on. In addition to the Spotlet class, it is used to handle events, as well as events for capturing handwriting input and keyboard press by Palm OS.
The following is a class that uses kjava to display simple text strings and buttons:
Import com. sun. kjava .*;
Public class HelloKjava extends Spotlet
{
Private static Button OKButton;
Public static Graphics g = Graphics. getGraphics ();
// Obtain the Graphics object
Public static void main (String args [])
{
HelloKjava hk = new HelloKjava ();
}
Public HelloKjava () // constructor of the HelloKjava class
{
OKButton = new Button ("OK", 84,140 );
Register (NO_EVENT_OPTIONS );
DrawScreen ();
}
Public void penDown (int x, int y)
{
If (OKButton. pressed (x, y )){
System. exit (1 );
}
}
Public void drawScreen ()
{
G. clearScreen (); // clear the screen
G. drawString ("Hello KJava", 20, 10); // draw the string on the screen.
OKButton. paint ();
}
}
There is also a class com. sun. kjava. Database, which is in a method that reaches the interface of the Palm Database application. This means that it is very primitive and does not provide full access to any content in the Palm database. It only allows setting and obtaining byte arrays; it does not allow access by typing, except by record ID (an integer ). Because the database can only understand byte arrays, the data given to you means that you need to parse these byte arrays into meaningful fields.
Ii. Kawt Solution
Kawt is also an Abstract Window Toolkit (Abstract Window Toolkit) of KVM. Kaw provides a more common set of application interfaces for Java Programmers. For example, it uses a general layout manager (except GridBag) in addition, it allows you to set listeners for those components. In other words, the Kawt does not include the Spotlet mechanism. Buttons, panels, labels, text boxes, and other AWT classes are available, as well as custom classes: FtpShel, TabbedPane, and GifLoader. There is also a java class. io. file is an abstract class that uses standard Palm database files to store data directories or File structures.
With Kawt, the program we compiled is as follows:
Import java. awt .*;
Import java. awt. event .*;
Public class HelloKawt extends Frame implements ActionListener
{
Button OKBtn = new Button ("OK ");
Label lbl = new Label ("Hello Palm ");
Public static void main (String args [])
{
New HelloKawt ();
}
Public HelloKawt ()
{
OKBtn. addActionListener (this );
This. add ("South", OKBtn );
This. add ("Center", lbl );
Pack ();
This. show ();
}
Public void actionreceivmed (ActionEvent AE)
{
System. exit (1 );
}
}
Although Kawt provides a better set of classes than kjava, it is actually based on kjava. Therefore, it lacks database classes. This is a serious problem for developing the Palm program. In general, any commercial application needs to store data on the device, and then synchronize with the desktop, kjava. database Synchronization is a bit problematic because it does not include the categories that HotSync software expects, and it does not allow access to the attribute bits of each "local" palm Database file that contains the initial record, even if the PDA Profile version is used, this cannot be solved, because the profile target is a common PDA rather than a special Palm OS. However, the Kawt team has done a great job after all, which makes it easy for programmers who are writing Palm programs to use Java programming.
Iii. IBM Solutions
IBM has its own virtual machine called J9-it is superior to KVM in many aspects, and Visual Age Micro Edition supports J9, which we all know, visual Age Micro Edition is an IDE from Object Technology International, and Object Technology International is a subsidiary of IBM. VAME is a complete development tool that provides full access permissions to the interfaces of the Palm OS application. However, this requires some costs. Although VAME is a Java tool, it provides packaging of Local C methods using the Palm application interface. That is to say, the method called in VAME is exactly the same as the method you see in C. Although it is not a bad thing to understand the operating system that your application is running, you need to be very familiar with the method features of developing the C application interface of Palm, if you are just a Java developer, this becomes a problem. This is a drawback. the engineers who develop VAME seem to have noticed this and try to improve it.
The following is a routine written using VAME:
Import com. ibm. oti. palmos .*;
Import com. ibm. oti. palmos. util. OSX;
Public class HelloJ9 implements OSConsts {
Public static void main (String [] args ){
CharPtr title = new CharPtr ("IBM Vame Demo ");
EventType event = new EventType ();
Try {
FormType form = OS. FrmNewForm (0, title, 0, 0,160,160, 0, 0, 0 );
OS. FrmSetActiveForm (form );
OS. FrmDrawForm (form );
OSX. WinDrawChars ("Hello J9! ", 5, 30 );
While (true ){
OS. EvtGetEvent (event,-1 );
If (OS. SysHandleEvent (event) = 0 ){
If (event. getEType () = appStopEvent ){
OS. FrmEraseForm (form );
OS. FrmDeleteForm (form );
Return;
}
}
}
} Finally {
Title. dispose ();
Event. dispose ();
OS. FrmCloseAllForms ();
}
}
}
As you can see, this program is not the same as the previous examples. If you can overcome this obstacle, your application performance will be far better than a KVM-based application. Other distinctive advantages of VAME are that it can access all local application interface calls