O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

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 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, ...

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