Solved

How To Launch A .hlp or html File From Java

Posted on 2003-11-23
9
439 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 65
hibernate insert example 13 34
Delete Android all or certain applications data programmatically 9 69
jmss example java 2 23
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 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