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

📄 hyperlinkdemo.java

📁 《java事件处理指南》一书的代码,好东西
💻 JAVA
字号:
import javax.swing.*;import javax.swing.event.*;import java.io.*;public class HyperlinkDemo extends JFrame implements HyperlinkListener{   private JEditorPane jep = null;   public HyperlinkDemo()    {/*  A JEditorPane object is initialized with an HTML file.    *//*  The JEditorPane registers a HyperlinkListener             *//*  and is added to the content pane of a JFrame.             *//*  NOTE:  you will have to change the html file location     *//*  to whatever it should be on your system.                  */      try      {         jep = new JEditorPane( "file:/usr/people/palmer/Java_Event/CD_examples/TheBoys.html");         jep.setContentType("text/html");         jep.setEditable(false);      }      catch (IOException ioe)      {         ioe.printStackTrace(System.err);         System.exit(1);      }      jep.addHyperlinkListener(this);      getContentPane().add(new JScrollPane(jep));      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      setBounds(100, 100, 400, 400);      setVisible(true);   }/*  When the user clicks on a hyperlink in one of the HTML pages,    *//*  a HyperlinkEvent is generated and sent to the hyperlinkUpdate()  *//*  method.  The event is used to obtain the URL associated with     *//*  the hyperlink and the HTML page displayed by the JEditorPane     *//*  is changed to be the one represented by the hyperlink.           */   public void hyperlinkUpdate(HyperlinkEvent event)   {      try      {         if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED )         {           jep.setPage(event.getURL());         }      }      catch (IOException ioe)      {         ioe.printStackTrace(System.err);      }   }   public static void main(String args[])    {      HyperlinkDemo demo = new HyperlinkDemo();   }}

⌨️ 快捷键说明

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