📄 accessibilitydemo2.java
字号:
// AccessibilityDemo2.java
import javax.accessibility.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class AccessibilityDemo2 extends JFrame
{
AccessibilityDemo2 (String title)
{
super (title);
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
});
JToolBar toolBar = new JToolBar ();
Action a = new AbstractAction ("Demo")
{
public void actionPerformed (ActionEvent e)
{
System.out.println ("Action taken.");
}
};
JButton b = toolBar.add (a);
b.setText ("Demo Button");
b.setToolTipText ("Press me to take action.");
JMenu mainMenu = new JMenu ("Menu");
JMenuItem mi = mainMenu.add (a);
mi.getAccessibleContext ().setAccessibleName ("Menu item");
JMenuBar mb = new JMenuBar ();
mb.add (mainMenu);
setJMenuBar (mb);
JPanel pane = new JPanel ();
pane.setLayout (new BorderLayout ());
pane.setPreferredSize (new Dimension (200, 100));
pane.add (toolBar, BorderLayout.NORTH);
setContentPane (pane);
pack ();
setVisible (true);
}
public static void main (String [] args)
{
AccessibilityDemo2 ad2;
ad2 = new AccessibilityDemo2 ("Accessibility Demo2");
try
{
Thread.sleep (5000);
}
catch (InterruptedException e) {}
ad2.dumpActionInfo (ad2.getAccessibleContext ());
}
void dumpActionInfo (AccessibleContext ac)
{
AccessibleAction aa = ac.getAccessibleAction ();
if (aa != null)
{
String s = ac.getAccessibleName ();
System.out.println (s);
int count = aa.getAccessibleActionCount ();
for (int i = 0; i < count; i++)
{
s = aa.getAccessibleActionDescription (i);
System.out.println ("Description = " + s);
}
}
int nChildren = ac.getAccessibleChildrenCount ();
for (int i = 0; i < nChildren; i++)
dumpActionInfo (ac.getAccessibleChild (i)
.getAccessibleContext ());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -