Solved

How To Launch A .hlp or html File From Java

Posted on 2003-11-23
9
421 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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:
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.

910 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

22 Experts available now in Live!

Get 1:1 Help Now