Solved

How To Launch A .hlp or html File From Java

Posted on 2003-11-23
9
412 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
  • 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now