2012-01-11 73 views
1

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

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 

当我点击HelpContent(menuItem)时,它应该打开一个Master.hs文件,但我没有收到任何输出和错误。如果我打印该帮助集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     
} 
+0

*“但我没有得到任何输出和错误”*您如何运行GUI? (例如从命令行,双击一个Jar,使用IDE启动它。) – 2012-01-11 11:11:40

+0

是的。它接受,如果我给了javahelp它也给出相同的输出。 – javasi 2012-01-11 11:14:25

+0

请给我一个解决方案来解决这个问题。 – javasi 2012-01-11 11:48:56

回答

0
public javahelp1(){ 

我相当新到Java,但我能看到的唯一的事情是,在顶部,这是你说的。是否有可能忘记说公共无效,并且你试图声明一种方法?它可能是这方面的一些东西。我希望这有助于:)