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 check boxes, which are
repeatedly updated when the mouse comes to rest over an accessible
component for longer than half a second.
Note that while using JDK 1.2 accessibility, we had to check to see
if the GUI was ready for us to start firing accessibility-related
commands to it. 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 makes use of the
GUIInitialized-Listener interface, which is
explained earlier in the chapter.
Finally, note that we have a single button in our assistive example that performs to 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 off the action.
//
AssistiveExample.java // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.accessibility.*; import com.sun.java.accessibility.util.*; public class AssistiveExample extends JPanel implements MouseMotionListener, ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access