The Java platform is becoming increasingly popular for developing desktop applications. In order to comply with standard Windows applications ergonomics, it is essential that accessibility barriers do not exist during application development.

Early releases of the Java API did not have native support for accessibility and assistive devices, thus potentially rendering Java products unusable to many visually impaired users. In an attempt to resolve the situation, Sun Microsystems released the Java Accessibility API (JAAPI). The JAAPI makes GUI component information available to assistive technologies, giving users alternative presentation and control of Java applications.

Accessibility on the Java platform consists of four basic elements:

  • JAAPI: Provides some kind of a contract between a Java application and the assistive technology (such as a screen reader or Braille display device).
  • Java Accessibility Utilities: Provides the ability to get the information from the application and process it for further displaying with special devices. They help assistive technologies monitor component-related events and get additional information about the GUI, such as the current position of the mouse, or the window that currently has focus.
  • Java Access Bridge (JAB): This is the most important element in providing accessibility to the Java platform under the Windows operating system. It was introduced in J2SE 1.3.
  • Java Foundation Classes (JFC): This is a library of GUI components, which fully implement the JAAPI.

JAAPI

The Accessibility API comprises a set of interfaces and classes. The main interface is the Accessible interface; all components that support accessibility must implement this interface. The Accessible interface defines one method, getAccessibleContext. When called on an accessible component, getAccessibleContext returns an AccessibleContext object. This object contains a basic set of accessibility information about the component, such as the component's accessible name, description, role, parent, and children, as well as the component's state. For example, if the component is a window, AccessibleContext indicates whether the window is active.

Most Swing (JFC) components, such as JButton and JTextArea, implement the Accessible interface. You can use the setAccessibleName and setAccessibleDescription methods of AccessibleContext to set an accessible name and description for the button. The code below offers an example of a simple application that displays a button and makes it accessible.

importjava.awt.*;

import javax.swing.JButton;

import javax.swing.JPanel;

import javax.swing.JFrame;

import javax.accessibility.*;



public class AccessSimpleButton extends JPanel {
    
    public AccessSimpleButton() {
        JButtonaButton = new JButton("Button");
       aButton.getAccessibleContext().         
                setAccessibleName("Button");    
        String desc = "This is a simple button";
        aButton.getAccessibleContext().         
                setAccessibleDescription(desc); 
        add(aButton);
    }


    public static void main(String[] args) {
        JFrame frame = new JFrame(
                                 "AccessSimpleButton");
        frame.getContentPane().
                          add(new AccessSimpleButton(), 
                                  BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }

}

In addition to methods for setting and getting basic accessibility information, AccessibleContext has methods for retrieving information about components that have special types of characteristics. For example, a component that displays text can make the text accessible to an assistive technology by implementing the AccessibleText interface; the getAccessibleText method of AccessibleContext returns the accessible text for a component that implements the AccessibleText interface. An assistive technology could then use AccessibleText interface methods to perform actions on the text, such as retrieve selected text.

Interpreting Java This was published in Interpreting Java, check every Tuesday for more stories

Related links

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

Log in


Sign up | Forgot your password?

What's on?