⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accessibilitydemo4.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
// AccessibilityDemo4.java

import javax.accessibility.*;

import javax.swing.*;
import javax.swing.event.*;

import java.awt.*;
import java.awt.event.*;

import java.net.*;

class AccessibilityDemo4 extends JFrame
                         implements ActionListener, HyperlinkListener
{
   JEditorPane view;
   JTextField commandLine;

   AccessibilityDemo4 (String title)
   {
      super (title);

      addWindowListener (new WindowAdapter ()
                         {
                             public void windowClosing (WindowEvent e)
                             {
                                System.exit (0);
                             }
                         });

      commandLine = new JTextField ();
      commandLine.addActionListener (this);
      getContentPane ().add (commandLine, BorderLayout.NORTH);

      view = new JEditorPane ();
      view.setEditable (false);
      view.setPreferredSize (new Dimension (400, 400));
      view.addHyperlinkListener (this);

      getContentPane ().add (view, BorderLayout.CENTER);

      pack ();
      setVisible (true);
   }

   public void actionPerformed (ActionEvent e)
   {
      try
      {
         URL url = new URL (e.getActionCommand ());
         view.setPage (url);
         commandLine.setText (url.toExternalForm ());
      }
      catch (MalformedURLException e2)
      {
         System.out.println ("Bad URL: " + e.getActionCommand ());
      }
      catch (java.io.IOException e2) {}
   }

   public void hyperlinkUpdate (HyperlinkEvent e)
   {
      try
      {
         view.setPage (e.getURL ());
         commandLine.setText (e.getURL ().toExternalForm ());
      }
      catch (java.io.IOException e2) {}
   }

   public static void main (String [] args)
   {
      AccessibilityDemo4 ad4;
      ad4 = new AccessibilityDemo4 ("Accessibility Demo4");

      try
      {
          Thread.sleep (10000);
      }
      catch (InterruptedException e) {}

      ad4.dumpHypertextInfo (ad4.getAccessibleContext ());
   }

   void dumpHypertextInfo (AccessibleContext ac)
   {
      AccessibleText at = ac.getAccessibleText ();

      AccessibleHypertext ah = null;
      if (at instanceof AccessibleHypertext)
          ah = (AccessibleHypertext) at;

      if (ah != null)
      {
          int nLinks = ah.getLinkCount ();

          for (int i = 0; i < nLinks; i++)
          {
               AccessibleHyperlink ahl = ah.getLink (i);

               int nActions = ahl.getAccessibleActionCount ();

               for (int j = 0; j < nActions; j++)
               {
                    String s = ahl.getAccessibleActionDescription (j);
                    System.out.println ("Action = " + s);
               }
          }

          return;
      }
            
      int nChildren = ac.getAccessibleChildrenCount ();

      for (int i = 0; i < nChildren; i++)
           dumpHypertextInfo (ac.getAccessibleChild (i)
                                .getAccessibleContext ());
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -