Microsoft SDK for Java

Input Method Editors

An input method editor (IME) is a program that allows computer users to enter complex characters and symbols, such as Japanese Kanji characters, by using a standard keyboard. Internationalized versions of Microsoft® Windows® provide native system IMEs for locales with languages using non-Latin alphabets (for example, Japanese, Korean, Traditional Chinese, and Simplified Chinese). The Microsoft virtual machine provides IME support for Java applications with an Input Method Manager (IMM) that hosts Java-based IMEs, as well as native system IMEs.

Native System IMEs

The Microsoft VM supports existing native system IMEs interchangeably with Java-based IMEs. However, there are some limitations associated with using system IMEs. You can use a Java-based IME on any system, regardless of what language the system is localized for, as long as the Microsoft VM is installed. With native system IMEs, however, you are limited to IMEs supported by the host system.

Java-Based IMEs

The Microsoft VM fully supports IMEs written in the Java language. Java-based IMEs provide more flexibility and control for applications than native system IMEs. The following is a summary of the features of Java-based IMEs.

Feature Description
Unicode-based Java IMEs can be used with any version of Microsoft Windows.
Cross-platform Java IMEs will run on any system that has the Microsoft VM installed.
Multilingual Java IMEs for different languages can be activated concurrently by a single Java application (provided the proper fonts are installed on the user's system).
Web-downloadable Java IMEs can be packaged and downloaded with applets or downloaded at the discretion of the user.
Managed by the application Applications can control Java IME interface elements such as composition, status, and candidate windows.
Secure Java IMEs follow normal Java security rules and run in the "sandbox" with Java applications.

Writing a Java-Based Input Method Editor

The com.ms.util.InputMethod package contains the following classes for creating Java-based IMEs:

Note   The Microsoft SDK for Java includes a sample application, SampleIME, that illustrates how to write a simple, Java-based IME located in %SDKDIR%\Samples\International\Sampleime. For more information, see the Internationalization Samples Overview. For information about other samples in this SDK, see the Samples Overview.

Handling Keystrokes

Keystrokes are passed from the Microsoft virtual machine to the IMM, which routes them to the IME. To receive keystrokes, the IME must override the InputMethodListener.handledKey method. The imeCallback parameter in InputMethodListener.handledKey specifies an InputMethodCallback object that allows the IME to send messages back to the Microsoft VM. When composition is complete, the IME should use the InputMethodCallback.handleIMEChar method to return the composed Unicode character to the Microsoft VM.

Note   Keystrokes are represented by virtual key codes defined by the KeyEvent class in the java.awt.event package. Keyboard state codes (ALT, CTRL, SHIFT, and so on) are defined in the InputManagerListener class.

Using IMEs with Java Applications

You do not have to do anything special with your Java application to use native system IMEs. If a native system IME is present on a system running the Microsoft VM, it will correctly process and route IME-composed strings to the application.

If you want to use a Java-based IME with your application, you must use the IMM to activate the IME that you want to use. The following list shows the classes you use to work with the IMM.

You must set the current IMM before activating an IME.

Example

The following code shows how to set the default IMM and install an IME:

InputManagerListener imm;
MyIME ime;

// Set default IMM
imm = com.ms.lang.SystemX.getDefaultInputManager ();
com.ms.lang.SystemX.setInputManager (imm, true);
if (imm != null)
{
    // Instantiate IME.
    ime = new MyIME () ;

    if (ime != null)
    {
        // Set IME to be current IME and activate it.
        imm.setInputMethod (ime);
        ime.activate ();
    }
}

© 1999 Microsoft Corporation. All rights reserved. Terms of use.