📄 htmlframedemo.java
字号:
import javax.swing.*;import javax.swing.event.*;import javax.swing.text.html.*;import java.io.*;public class HTMLFrameDemo extends JFrame implements HyperlinkListener{ private JEditorPane jep = null; public HTMLFrameDemo() {/* A JEditorPane object is initialized with an HTML frame. *//* 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 machine. */ try { jep = new JEditorPane( "file:/usr/people/palmer/Java_Event/CD_examples/Frame.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 tested to see if it is a plain old *//* HyperlinkEvent or an HTMLFrameHyperlinkEvent. If it is the *//* latter, the HTMLDocument associated with the JEditorPane is *//* used to process the event and update the display. Otherwise, *//* the display is updated by calling the setPage() methods. */ public void hyperlinkUpdate(HyperlinkEvent event) { if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) { JEditorPane pane = (JEditorPane)event.getSource(); if ( event instanceof HTMLFrameHyperlinkEvent ) { HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)event; HTMLDocument document = (HTMLDocument)pane.getDocument(); document.processHTMLFrameHyperlinkEvent(evt); } else { try { jep.setPage(event.getURL()); } catch (IOException ioe) { ioe.printStackTrace(System.err); } } } } public static void main(String args[]) { HTMLFrameDemo demo = new HTMLFrameDemo(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -