Solved

How To Launch A .hlp or html File From Java

Posted on 2003-11-23
9
447 Views
Last Modified: 2008-03-17
Hi, I have A Small Program With Some Buttons, when the guide button is clicked I would like for java to launch my guide.html file in the browser, if this is not posible, please give me a alternative, thanks the following is my current code:
class helpPanel extends JPanel
{
      //Constructor For Help Panel
      public helpPanel()
      {
            //Creating Buttons To Display Image
            JButton guideButton = new JButton(new ImageIcon("images/butt-guide.jpg"));
            JButton creditsButton = new JButton(new ImageIcon("images/butt-credits.jpg"));
            JButton contactButton = new JButton(new ImageIcon("images/butt-contact.jpg"));
            
            //Adding Components
            add(guideButton);
            add(creditsButton);
            add(contactButton);
            
            //Adding ActionListeners To Components
            guideButton.addActionListener(new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        guideAction();
                  }
            });

            creditsButton.addActionListener(new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        creditsAction();
                  }
            });

            contactButton.addActionListener(new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        contactAction();
                  }
            });
      }
      
      //Action Definitions
      private void guideAction()
      {
            //This is where the code should be to launch the guide.hlp or guide.html
            Toolkit.getDefaultToolkit().beep();
      }
            
      private void creditsAction()
      {
            new Credits();
            Toolkit.getDefaultToolkit().beep();
      }
      
      private void contactAction()
      {
            new Contact();
            Toolkit.getDefaultToolkit().beep();
      }
}
0
Comment
Question by:isaacmc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9808322
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9808329
ry {
        String ls_str;

        Process ls_proc = Runtime.getRuntime().exec("winhelp myhelp.hlp");
}
catch(Exception exe)
{
}

if this is not executed give the total path by identifying it's path

for e.g "c:\\windows\\winhelp.exe myhelp.hlp"

0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9808334
for launching html files

 Process ls_proc = Runtime.getRuntime().exec("iexplore myhelp.html");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:isaacmc
ID: 9808345
sudhakar_koundinya

is there any apis's or anything i have to import and is that the only code i have to add to my actionlistener
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 120 total points
ID: 9808390
import java.io.* is more than enough


class Launch
{
      public static void main(String[] args) throws Exception
      {
            
             try
            {
                   Process ls_proc = Runtime.getRuntime().exec("c:\\windows\\winhelp.exe");
            }
            catch(Exception ex)
            {
                  System.out.println("cannot create proccess. Executable not found error");
            }

      }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9808397
make sure that you should give correct path for both executable and help file

for example if the exe is in windows directory and help file is in your directory you should give like this

 Process ls_proc = Runtime.getRuntime().exec("c:\\windows\\winhelp.exe  c:\myapp\myhelp.hlp");

but make sure to import java.io.* package
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9808785
does that gives any help
0
 

Author Comment

by:isaacmc
ID: 9808811
could you please give me a whole working code using swing with a jframe and a button with a actionlistener thats works with this code, thanks.
0
 

Author Comment

by:isaacmc
ID: 9809113
sudhakar_koundinya

thanks alot man
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 107
spring jars download 1 53
batch vs regular insert in spring DAO 2 22
Java List 4 38
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question