Solutions for writing Palm OS programs in Java

Source: Internet
Author: User
Now, we use the Java language to write for the Palm OS Program The fields 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 Article 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 ();
File: // obtain the graphics object

Public static void main (string ARGs [])
{
Hellokjava HK = new hellokjava ();
}

Public hellokjava () file: // 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 (); file: // clear the screen
G. drawstring ("Hello kjava", 20, 10); file: // 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, 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. The other distinctive advantage of vame is that it can access all local application interface calls. Using a pipe, you can create any palm database synchronously.


Iv. WABA/superwaba Solutions

WABA is another virtual machine. In terms of style, WABA is a bit like the intermediate products of kjava and kawt. It contains more GUI components than kjava and uses coordinates to place components on the screen, rather than using layout manager like kawt. The advantage of WABA is its speed, which is indeed much faster than KVM. Moreover, if you think your application may not only be positioned in the Palm OS, you can also use WABA, because WABA can also run on Windows CE. WABA also has an extension called superwaba, which provides more functions.

Here is a small application program written using WABA, which uses an additional class to set the title:
Import WABA. UI .*;
Import WABA. FX .*;

Public class hellowaba extends mainwindow
{

Button closebutton;

Public hellowaba ()
{
Title = new title ("hellowaba ");
Title. setrect (0, 0, this. Width, 15 );
Add (title );

Closebutton = new button ("close ");
Closebutton. setrect (0, this. Height-15, 44, 15 );
Add (closebutton );
}

Public void onevent)
{
If (event. type = controlevent. Pressed)
{
If (event.tar get = closebutton)
Exit (0 );
}
}
}

WABA also has many advantages: the ability to copy and paste the clipboard, access the system keyboard to make it easier to input text, and there is also a class that encapsulates some virtual machine details, allow you to determine the platform and Rom version on which the virtual machine is running.

V. Summary

 

The solution for writing Palm OS applications in Java depends on several factors: whether your goal is only the Palm OS; for development, speed and accessibility are more important; we are still far away from deciding what solution to use to develop the palm program, because this field will change dramatically in the future. In future articles, I will introduce in detail applications that can be used for Palm OS or other small devices using j2-bit and WABA.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.