O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interfacing with Accessibility

The following code shows how to create a simple assistive technology that can monitor events on the system event queue and interface with accessible components. The example consists of one class, AssistiveExample. This class creates a small window containing two labels and five checkboxes, which are repeatedly updated when the mouse comes to rest over an accessible component for longer than half a second.

Note that while using 1.2 or higher accessibility, we have to check to see if the GUI is ready for us to start firing accessibility-related commands. We do this by checking the EventQueueMonitor.isGUIInitialized( ) method. This method returns a boolean indicating whether the GUI will accept accessibility commands. If it does, then we’re fine. If it doesn’t, then we must register ourselves to be notified when the GUI becomes available. This uses the GUIInitializedListener interface, which we explained earlier.

To use the AssistiveExample class, simply create a new AssistiveExample object from an existing application. The constructor creates a frame and makes it visible. For an example, check the source of the BigExample class in the online code files for this chapter.

Finally, note that we have a single button in our assistive example that performs the first action reported by the accessible context. You can use the Tab key to bring this button into focus while pointing with the mouse, then press the space bar to fire the action.

// AssistiveExample.java ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required