Java by API/javax.accessibility/AccessibleComponent — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 17:43, 31 мая 2010

AccessibleComponent: getBackground()

import java.awt.Cursor;
import java.awt.Dimension;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton("OK");
    p.add(jb);
    getContentPane().add(p);
    pack();
    setVisible(true);
  }
  public static void main(String[] args) {
    MainClass f = new MainClass();
    f.dumpComponentInfo(f.getAccessibleContext());
  }
  void dumpComponentInfo(AccessibleContext ac) {
    AccessibleComponent ax = ac.getAccessibleComponent();
    if (ax != null) {
      String s = ac.getAccessibleName();
      if (s != null && s.equals("OK")) {
        System.out.println("Background color: " + ax.getBackground());
        System.out.println("Cursor: " + ax.getCursor());
        Cursor c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        ax.setCursor(c);
        System.out.println("Foreground color: " + ax.getForeground());
        System.out.println("Location: " + ax.getLocationOnScreen());
      }
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpComponentInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}





AccessibleComponent: getCursor()

import java.awt.Cursor;
import java.awt.Dimension;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton("OK");
    p.add(jb);
    getContentPane().add(p);
    pack();
    setVisible(true);
  }
  public static void main(String[] args) {
    MainClass f = new MainClass();
    f.dumpComponentInfo(f.getAccessibleContext());
  }
  void dumpComponentInfo(AccessibleContext ac) {
    AccessibleComponent ax = ac.getAccessibleComponent();
    if (ax != null) {
      String s = ac.getAccessibleName();
      if (s != null && s.equals("OK")) {
        System.out.println("Background color: " + ax.getBackground());
        System.out.println("Cursor: " + ax.getCursor());
        Cursor c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        ax.setCursor(c);
        System.out.println("Foreground color: " + ax.getForeground());
        System.out.println("Location: " + ax.getLocationOnScreen());
      }
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpComponentInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}





AccessibleComponent: getForeground()

import java.awt.Cursor;
import java.awt.Dimension;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton("OK");
    p.add(jb);
    getContentPane().add(p);
    pack();
    setVisible(true);
  }
  public static void main(String[] args) {
    MainClass f = new MainClass();
    f.dumpComponentInfo(f.getAccessibleContext());
  }
  void dumpComponentInfo(AccessibleContext ac) {
    AccessibleComponent ax = ac.getAccessibleComponent();
    if (ax != null) {
      String s = ac.getAccessibleName();
      if (s != null && s.equals("OK")) {
        System.out.println("Background color: " + ax.getBackground());
        System.out.println("Cursor: " + ax.getCursor());
        Cursor c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        ax.setCursor(c);
        System.out.println("Foreground color: " + ax.getForeground());
        System.out.println("Location: " + ax.getLocationOnScreen());
      }
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpComponentInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}





AccessibleComponent: getLocationOnScreen()

import java.awt.Cursor;
import java.awt.Dimension;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton("OK");
    p.add(jb);
    getContentPane().add(p);
    pack();
    setVisible(true);
  }
  public static void main(String[] args) {
    MainClass f = new MainClass();
    f.dumpComponentInfo(f.getAccessibleContext());
  }
  void dumpComponentInfo(AccessibleContext ac) {
    AccessibleComponent ax = ac.getAccessibleComponent();
    if (ax != null) {
      String s = ac.getAccessibleName();
      if (s != null && s.equals("OK")) {
        System.out.println("Background color: " + ax.getBackground());
        System.out.println("Cursor: " + ax.getCursor());
        Cursor c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        ax.setCursor(c);
        System.out.println("Foreground color: " + ax.getForeground());
        System.out.println("Location: " + ax.getLocationOnScreen());
      }
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpComponentInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}





AccessibleComponent: setCursor(Cursor cursor)

import java.awt.Cursor;
import java.awt.Dimension;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JFrame {
  MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton("OK");
    p.add(jb);
    getContentPane().add(p);
    pack();
    setVisible(true);
  }
  public static void main(String[] args) {
    MainClass f = new MainClass();
    f.dumpComponentInfo(f.getAccessibleContext());
  }
  void dumpComponentInfo(AccessibleContext ac) {
    AccessibleComponent ax = ac.getAccessibleComponent();
    if (ax != null) {
      String s = ac.getAccessibleName();
      if (s != null && s.equals("OK")) {
        System.out.println("Background color: " + ax.getBackground());
        System.out.println("Cursor: " + ax.getCursor());
        Cursor c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        ax.setCursor(c);
        System.out.println("Foreground color: " + ax.getForeground());
        System.out.println("Location: " + ax.getLocationOnScreen());
      }
    }
    int nChildren = ac.getAccessibleChildrenCount();
    for (int i = 0; i < nChildren; i++)
      dumpComponentInfo(ac.getAccessibleChild(i).getAccessibleContext());
  }
}