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

📄 helpdisplay.java

📁 一个用Java实现的小型
💻 JAVA
字号:
import java.net.*;public class HelpDisplay extends javax.swing.JFrame {  private final static String fileSeperator = System.getProperty("file.separator");  private final static String workingDir = System.getProperty("user.dir");  private static URL introPage;  private static URL pathPage;  private URLHistory history;    /** Creates new form HelpDisplay */  public HelpDisplay() {    initComponents();    history = new URLHistory(10);    try {      introPage = new URL("file:"+workingDir+fileSeperator+"docs"+fileSeperator+"index.html");      pathPage = new URL("file:"+workingDir+fileSeperator+"docs"+fileSeperator+"$APPPATHS");      mainEditorPane.setPage(introPage);      history.add(introPage);    } catch (Exception e) {      System.err.println("Cannot find help page "+e);    }  }    /** This method is called from within the constructor to   * initialize the form.   * WARNING: Do NOT modify this code. The content of this method is   * always regenerated by the Form Editor.   */  private void initComponents() {//GEN-BEGIN:initComponents    helpScrollPane = new javax.swing.JScrollPane();    mainEditorPane = new javax.swing.JEditorPane();    buttonPanel = new javax.swing.JPanel();    backButton = new javax.swing.JButton();    forwardButton = new javax.swing.JButton();    closeButton = new javax.swing.JButton();        addWindowListener(new java.awt.event.WindowAdapter() {      public void windowClosing(java.awt.event.WindowEvent evt) {        exitForm(evt);      }    });        helpScrollPane.setPreferredSize(new java.awt.Dimension(600, 300));    mainEditorPane.setEditable(false);    mainEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {      public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {        gotoURL(evt);      }    });        helpScrollPane.setViewportView(mainEditorPane);        getContentPane().add(helpScrollPane, java.awt.BorderLayout.CENTER);        buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));        backButton.setText("<<");    backButton.setEnabled(false);    backButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(java.awt.event.ActionEvent evt) {        goBack(evt);      }    });        buttonPanel.add(backButton);        forwardButton.setText(">>");    forwardButton.setEnabled(false);    forwardButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(java.awt.event.ActionEvent evt) {        goForward(evt);      }    });        buttonPanel.add(forwardButton);        closeButton.setText("Close");    getRootPane().setDefaultButton(closeButton);    closeButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(java.awt.event.ActionEvent evt) {        close(evt);      }    });        buttonPanel.add(closeButton);        getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);        pack();  }//GEN-END:initComponents  private void goForward(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goForward    try {      setPage(history.getNext());    } catch (Exception e) {      System.err.println("Couldn't get next page!");    }  }//GEN-LAST:event_goForward  private void goBack(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goBack    try {      setPage(history.getPrevious());    } catch (Exception e) {      System.err.println("Couldn't get previous page!");    }  }//GEN-LAST:event_goBack  private void gotoURL(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_gotoURL    if(evt.getEventType().equals(javax.swing.event.HyperlinkEvent.EventType.ACTIVATED)) {      try {        URL newPage = evt.getURL();        setPage(newPage);        history.add(newPage);      } catch (Exception e) {        System.err.println("Bad page: "+e);      }    }  }//GEN-LAST:event_gotoURL  private void close(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_close    exitForm();  }//GEN-LAST:event_close        private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm      exitForm();    }//GEN-LAST:event_exitForm        private void setPage(URL page) throws java.io.IOException {      if(page.equals(pathPage)) {        mainEditorPane.setDocument(mainEditorPane.getEditorKit().createDefaultDocument());        mainEditorPane.setContentType("text/html");        mainEditorPane.setText(getPathPage());      } else {        mainEditorPane.setPage(page);      }    }        /** Exit the Application */    private void exitForm() {      setVisible(false);    }        private String getPathPage() {      return "<HTML>\n<BODY>\n<FONT Size=\"+1\">File Paths You Might Need to Know</FONT>\n<P>\n"+      "<DL>\n<DT><B>What is my extensions directory?</B>\n"+      "<DD>It is <CODE>"+System.getProperty("java.ext.dirs")+"</CODE>.\n<P>\n"+      "<DT><B>Where are my preferences stored?</B>\n"+      "<DD>Preferences are stored in files ending in .def within your "+      "user directory, which is <CODE>"+CsltComm.prefsDir+"</CODE>.\n<P>\n"+      "<DT><B>What directory is ConsultComm running from?</B>\n"+      "<DD>The working directory for this applicaition is <CODE>"+System.getProperty("user.dir")+"</CODE>.\n<P>\n"+      "</DL>\n</BODY>\n</HTML>";    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JScrollPane helpScrollPane;    private javax.swing.JEditorPane mainEditorPane;    private javax.swing.JPanel buttonPanel;    private javax.swing.JButton backButton;    private javax.swing.JButton forwardButton;    private javax.swing.JButton closeButton;    // End of variables declaration//GEN-END:variables        private class URLHistory {      private URL[] historyList;      private int currIndex;      private int startIndex;      private int endIndex;      URLHistory() {        historyList = new URL[20];        startIndex = 0;        endIndex = 0;        currIndex = -1;      }      URLHistory(int size) {        historyList = new URL[size];        startIndex = 0;        endIndex = 0;        currIndex = -1;      }            protected URL getPrevious() {        if(--currIndex < 0) currIndex = historyList.length-1;        URL page = historyList[currIndex];        forwardButton.setEnabled(true);        if(! existsPrevious()) backButton.setEnabled(false);        return page;      }      protected URL getNext() {        currIndex = (currIndex+1)%historyList.length;        URL page = historyList[currIndex];        backButton.setEnabled(true);        if(! existsNext()) forwardButton.setEnabled(false);        return page;      }      protected boolean existsPrevious() {        return currIndex != startIndex;      }      protected boolean existsNext() {        return currIndex != endIndex-1;      }      protected void add(URL page) {        currIndex = (currIndex+1)%historyList.length;        historyList[currIndex] = page;        endIndex = (currIndex+1)%historyList.length;        if(endIndex == startIndex)          startIndex = (startIndex+1)%historyList.length;        forwardButton.setEnabled(false);        if(existsPrevious()) backButton.setEnabled(true);      }    }}

⌨️ 快捷键说明

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