?
Solved

How To Launch A .hlp or html File From Java

Posted on 2003-11-23
9
Medium Priority
?
463 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: 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
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!

 

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 480 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 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