1

我在我的项目中创建了一个类(javahelp),用于在单击帮助内容(菜单项)时获取 java 帮助文件。我更新安装javahelp-2.0_05在目录中

C:\Program Files\javahelp-2.0_05\demos\bin\hsviewer.jar

然后Java exe文件包含在目录中

C:\Program Files\Java\jdk1.6.0_24\bin\java.exe 

我的项目是在目录中创建的

E:\java\databaserecord\src\HelpFile\javahelp

然后我更新了目录中的java帮助文件夹

E:\java\databaserecord\build\classes\javahelp-2.0_05\demos\hs\merge\Master.hs 

当我单击 a 时HelpContent(menuItem),它应该打开一个Master.hs文件,但我没有得到任何输出和错误。如果我打印那个 HelpSet URL,它会显示这一行

file:/E:/java/databaserecord/build/classes/javahelp-2.0_05/demos/hs/merge/Master.hs

但它没有打开那个帮助页面。如何显示帮助集文件?

import java.net.*;
import javax.swing.*;
import javax.help.*;
import java.awt.event.*;


public class javahelp1 extends javax.swing.JFrame {


    public javahelp1() {
        initComponents();
    }
    //HelpSet hs;

     public void helpset(){
      try {
          ClassLoader cl = javahelp1.class.getClassLoader();
        URL hsURL = HelpSet.findHelpSet(cl, "javahelp-2.0_05/demos/hs/merge/Master.hs");
       System.out.println(hsURL);
      HelpSet hs = new HelpSet(cl, hsURL);
      HelpBroker hb = hs.createHelpBroker();
      new CSH.DisplayHelpFromSource(hb);

      } catch(Exception ee) {
          System.out.println(ee);
        System.out.println("HelpSet: "+ee.getMessage());
      }

   }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        Mnu01 = new javax.swing.JMenu();
        Mnu02 = new javax.swing.JMenu();
        MnuItm01 = new javax.swing.JMenuItem();
        MnuItm02 = new javax.swing.JMenuItem();
        MnuItm03 = new javax.swing.JMenuItem();
        MnuItm04 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setFont(new java.awt.Font("Arial", 0, 10));

        Mnu01.setMnemonic('F');
        Mnu01.setText("File");
        Mnu01.setToolTipText("Create a File");
        jMenuBar1.add(Mnu01);

        Mnu02.setMnemonic('H');
        Mnu02.setText("Help");
        Mnu02.setToolTipText("For Help");

        MnuItm01.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        MnuItm01.setText("Content1");
        MnuItm01.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnuItm01ActionPerformed(evt);
            }
        });
        Mnu02.add(MnuItm01);

        MnuItm02.setMnemonic('2');
        MnuItm02.setText("Content2");
        MnuItm02.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnuItm02ActionPerformed(evt);
            }
        });
        Mnu02.add(MnuItm02);

        MnuItm03.setMnemonic('3');
        MnuItm03.setText("Content3");
        MnuItm03.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnuItm03ActionPerformed(evt);
            }
        });
        Mnu02.add(MnuItm03);

        MnuItm04.setMnemonic('4');
        MnuItm04.setText("Content4");
        MnuItm04.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MnuItm04ActionPerformed(evt);
            }
        });
        Mnu02.add(MnuItm04);

        jMenuBar1.add(Mnu02);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 587, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 309, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void MnuItm02ActionPerformed(java.awt.event.ActionEvent evt) {                                         
           new javahelp2().setVisible(true);
}                                        

    private void MnuItm03ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        new javahelp3().setVisible(true);
    }                                        

    private void MnuItm04ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        new javahelp4().setVisible(true);
    }                                        

    private void MnuItm01ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            helpset();
    }                                        

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new javahelp1().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JMenu Mnu01;
    private javax.swing.JMenu Mnu02;
    private javax.swing.JMenuItem MnuItm01;
    private javax.swing.JMenuItem MnuItm02;
    private javax.swing.JMenuItem MnuItm03;
    private javax.swing.JMenuItem MnuItm04;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration                   
}
4

1 回答 1

0
public javahelp1(){

我对java很陌生,但我唯一能注意到的是在顶部,这就是你所说的。您是否有可能忘记说 public void 并且您试图声明一个方法?可能是这样的。我希望这可以帮到你 :)

于 2017-04-12T22:47:47.080 回答