digital media access group
...excellent accessibility research and consultancy
Accessible Java using JAAPI
By Niall O'Gribin, published 25th October 2004.
Java applets are increasingly popular as a way of delivering interactive web content - but what exactly are Java applets?
Java applets are simply a Java class that is loaded and run by Java application or a Web browser capable of running Java programs. Applets are frequently used to add multimedia effects and interactivity to Web pages, such as video displays, animations, calculators, real-time clocks, and interactive games.
Why is Java attractive to developers?
- Java programs are translated (compiled) into an architecture-independent Java bytecode. The user of a Java Program runs a Java Interpreter which performs the actions specified by the Java bytecode . This makes it possible to run a single Java program on many different types of computers.
- Tools for graphical user interface development are available for Java.
- Most popular web Browsers can download and run Java programs and applets.
- Java is free!
Due to the proliferation of Java applications and applets on the Internet, it is essential that accessibility barriers are not introduced during their development. Obviously the Web Content Accessibility Guidelines [1] still apply to the interface of a Java applet - for example it should be keyboard accessible, and it should not rely on colour as the only way of portraying information.
But, additional work is needed so that a Java applet can work with assistive technologies such as screen readers and Braille display devices can interact with Java technologies effectively. Early releases of the Java API (Application Programming Interface) did not have native support for accessibility, and assistive devices; thus (potentially) rendering Java products unusable to many blind and visually impaired people.
In an attempt to rectify the situation, Sun (the creators of Java) 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.
- The Java Accessibility API, which is an informational contract between a given Java technology-based applet or application and the assistive technology charged with revealing its inner working to the disabled user.
- The Java Accessibility Utilities, which allow an assistive technology to actually get to the information offered up via the accessibility API - the ability to load itself into the Java virtual machine, methods for listening to events in a running application, and more.
- The Java Access Bridge [2] is a particularly important element in providing increased accessibility to the Java platform. Users of assistive technologies are often using an assistive technology specific to their native platform (Apple Macintosh, Windows and so on). For the assistive technology to make use of the information offered by the Java Accessibility API, it must have access to the Java virtual machine. It doesn't usually make sense to have separate assistive technologies - for example a screen reader for Windows, and a separate screen reader for Java applications. Using the Java Access Bridge, a single assistive technology can effectively live in both worlds.
- The Java Foundation Classes, a library of graphical user-interface components. These components fully implement the Java Accessibility API, which means that Application developers can take advantage of this easy way to incorporate accessibility into their designs. Components can be manipulated solely from the keyboard.
Interface Accessible is the main interface for the accessibility package. All components that support the accessibility package must implement this interface. It contains a single method, getAccessibleContext(), which returns an instance of the class AccessibleContext.
Below is some Sample Code to show how easy it is to implement accessible components in Java (in this case a button). (Example code adapted from [3])
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.accessibility.*;
public class AccessSimpleButton extends JPanel {
public AccessSimpleButton() {
JButton aButton = 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 f = new JFrame("Accessible Button");
f.getContentPane().add(new AccessSimpleButton(),BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
Using the Access Bridge, it is possible for screen reading technology to access the content of the above applet.
The JAAPI was released in 1999, yet a search on Google does not yield many snippets of sample code, nor indeed example applications that use the API. Quantifying how many accessible Java applications & applets are available is difficult; and in a discussion of online chat programs, WebAIM are unaware of any screenreader-accessible Java-based web chat programs [4].
However it is clear that the tools to create accessible Java exis and that they should be used. It is also worth reiterating that developers using JAAPI in their interfaces should still follow best practice in interface design, for example [5], rather than using JAAPI as a substitute!
It should also be noted that the <applet> tag is officially deprecated in all definitions of HTML from 4.0 onwards, and instead, one must use the <object> tag. However, be aware that support for <object> is poor amongst older browsers, particularly for Netscape version 4 browsers.
Additionally, as some web-browsers do not support Java, or do not have a Java Virtual Machine (JVM) installed; developers should also provide a text-only alternative in the <object> definition. To do this, just add plain text enclosed within the <object> element.
One guideline of the WCAG requires developers to ensure that equivalents for dynamic content are updated when the dynamic content changes [6]. This can be challenging, particularly where an applet provides complex functionality, and deciding what text-only alternative to use may prove difficult in some cases (for example, providing an alternative for an interactive game applet). The key is to make sure as far as possible that anyone unable to access the applet can access the information it provides by alternative means.
References
- W3C Web Content Accessibility Guidelines version 1.0 - http://www.w3.org/TR/WCAG10/
- Java Access Bridge - http://java.sun.com/products/accessbridge
- What's New with Accessibility - http://java.sun.com/developer/technicalArticles/GUI/accessibility2
- Accessibility and the Swing Set - http://java.sun.com/products/jfc/tsc/articles/accessibility
- The WebAIM project: Accessibility of Online Chat Programs http://www.webaim.org/techniques/articles/chats
- HTML Techniques for Web Content Accessibility Guidelines 1.0 http://www.w3.org/TR/WCAG10-HTML-TECHS/objects
Further Reading
- IBM Accessibility Center - http://www-3.ibm.com/able/
- IBM Guidelines for Writing Accessible Applications Using 100% Pure Java - http://www.dinf.ne.jp/doc/english/Us_Eu/conf/csun_98/csun98_051g.htm
- First principles of Interaction design - http://www.asktog.com/basics/firstPrinciples.html
- Paciello M (2000) Web Accessibility for People with Disabilities. CMP Books