An example of getting the Accessible information from a Button object : Accessible « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » AccessibleScreenshots 
An example of getting the Accessible information from a Button object
An example of getting the Accessible information from a Button object


/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly 
*/
// ActionExampleButton.java
//An example of getting the Accessible information from a Button object.
//(You could see this information by attaching an AssistiveExample object
//to the button. See BigExample.java for an example of that attachment.)
//

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleStateSet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class ActionExample extends Button implements ActionListener, Accessible {

  public ActionExample() {
    super("Press this Button");
    addActionListener(this);
  }

  public AccessibleContext getAccessibleContext() {
    return (new ActionAccessibleContext());
  }

  public void actionPerformed(ActionEvent e) {
    System.out.println("The button was pressed!");
  }

  public void processActionEvent(ActionEvent e) {
    super.processActionEvent(e);
  }

  // This class contains the accessible context for the component. Many
  // abstract methods simply call the SwingUtilities class to get the job
  // done; this is advised if you can get away with it. Otherwise, see the
  // source code for SwingUtilities.
  class ActionAccessibleContext extends AccessibleContext {

    public ActionAccessibleContext() {
      super();
      setAccessibleName("Button");
      setAccessibleDescription("Press the Button");
    }

    public AccessibleRole getAccessibleRole() {
      // Fill in whatever role you want here
      return (AccessibleRole.AWT_COMPONENT);
    }

    public AccessibleStateSet getAccessibleStateSet() {
      return SwingUtilities.getAccessibleStateSet(ActionExample.this);
    }

    public int getAccessibleIndexInParent() {
      return SwingUtilities
          .getAccessibleIndexInParent(ActionExample.this);
    }

    public int getAccessibleChildrenCount() {
      return SwingUtilities
          .getAccessibleChildrenCount(ActionExample.this);
    }

    public Accessible getAccessibleChild(int i) {
      return SwingUtilities.getAccessibleChild(ActionExample.this, i);
    }

    public Locale getLocale() {
      //  Ask the component what its locale is
      return ActionExample.this.getLocale();
    }

    public AccessibleAction getAccessibleAction() {
      return new AccessAction();
    }
  }

  // This class implements the AccessibleAction interface. Essentially, there
  // is only one action that is the equivalent of pushing the button.
  class AccessAction implements AccessibleAction {

    final int NUMBER_OF_ACTIONS = 1;

    final String DESCRIPTION = "Presses the button";

    public int getAccessibleActionCount() {
      return NUMBER_OF_ACTIONS;
    }

    public String getAccessibleActionDescription(int i) {
      if (i == 0)
        return (DESCRIPTION);
      else
        return null;
    }

    public boolean doAccessibleAction(int i) {
      if (i == 0) {
        // Simulate pressing a button
        ActionExample.this.processActionEvent(new ActionEvent(this,
            ActionEvent.ACTION_PERFORMED, ActionExample.this
                .getActionCommand()));
        return true;
      else
        return false;
    }
  }

  public static void main(String s[]) {

    ActionExample example = new ActionExample();

    JFrame frame = new JFrame("AccessibleAction Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(example, BorderLayout.CENTER);
    frame.setSize(100100);
    frame.setVisible(true);
  }
}

           
       
Related examples in the same category
1. A GUI to show accessible information coming from the components in an
w_w_w___.__j_av_a___2___s__.co_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.