Subpages:
1. Java 2 Accessibility API overview
2. Following accessibility guidelines
3. Accessibility support for custom components
24.2 Following accessibility guidelines
Let's take a look at how the guidelines for writing an accessible application can be fully adhered to in one of our previous examples: the FTP Client application from chapter 13. As you will see, only minor changes need to be made for full compliance.

Figure 24.1 FTP Client application with added accessibility support, and monitored using the Explorer utility.
<<file figure24-1.gif>>
The Code: Access1.java
see \Chapter24\1
// Unchanged imports from section 13.5
public class Access1 extends JFrame
{
// Unchanged code from section 13.5
public Access1()
{
super("FTP Client [Accessible]");
getContentPane().setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new DialogLayout2(10, 5));
p.setBorder(new EmptyBorder(5, 5, 5, 5));
JLabel lbl = new JLabel("User name:");
lbl.setDisplayedMnemonic('n');
p.add(lbl);
m_txtUser = new JTextField("anonymous");
m_txtUser.setToolTipText("User name");
p.add(m_txtUser);
lbl.setLabelFor(m_txtUser);
lbl = new JLabel("Password:");
lbl.setDisplayedMnemonic('p');
p.add(lbl);
m_txtPassword = new JPasswordField();
m_txtPassword.setToolTipText("Password");
p.add(m_txtPassword);
lbl.setLabelFor(m_txtPassword);
lbl = new JLabel("URL:");
lbl.setDisplayedMnemonic('u');
p.add(lbl);
m_txtURL = new JTextField();
m_txtURL.setToolTipText("URL");
p.add(m_txtURL);
lbl.setLabelFor(m_txtURL);
lbl = new JLabel("File:");
lbl.setDisplayedMnemonic('l');
p.add(lbl);
m_txtFile = new JTextField();
m_txtFile.setToolTipText("File");
p.add(m_txtFile);
lbl.setLabelFor(m_txtFile);
// Unchanged code from section 13.5
p.add(new DialogSeparator());
m_btPut = new JButton("Put");
m_btPut.setToolTipText("Upload file");
// Unchanged code from section 13.5
p.add(m_btPut);
m_btGet = new JButton("Get");
m_btGet.setToolTipText("Download file");
// Unchanged code from section 13.5
p.add(m_btGet);
m_btFile = new JButton("File");
m_btFile.setToolTipText("Select file");
// Unchanged code from section 13.5
p.add(m_btFile);
m_btClose = new JButton("Close");
m_btClose.setToolTipText("Quit application");
// Unchanged code from section 13.5
p.add(m_btClose);
// Unchanged from section 13.5
Understanding the Code
Class Access1
Compared to the example in chapter 13 we have made some a very minor amount of changes, and those we did make are quite simple. All labels receive a displayedMnemonic property and are associated with the corresponding text fields using the setLabelFor() method. We've also added tooltip text for each text field and label.
Running the Code
At this point you can compile and execute this example. Figure 24.1 shows our FTP Client application and the Explorer accessible utility displaying events generating by that application. Unfortunately we cannot implement actual support for disabled users because no real assistive technologies are currently available.



RSS feed Java FAQ News