Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Loading HTML

After loading my Java Program, I want to click a button, like my help menu button, and load an HTML document or a browser with some information thats already there, like a help file.

How would I do this?  How would I point my actionlistener to that html page and load that html page, my Program is not an applet, its a Java program.
0
gujuraja143
Asked:
gujuraja143
  • 2
  • 2
1 Solution
 
objectsCommented:
Your action listener should use Runtime.exec() to launch your browser.

Here's an article describing how to do this:
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html 

0
 
OviCommented:
/*
 * Created on Mar 25, 2003
 *
 * To change this generated comment go to
 * Window>Preferences>Java>Code Generation>Code Template
 */
package tests.swing.text;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

/**
 * @author ovi
 */
public class URLBrowser {

     public static void main(String[] args) {
          JFrame f = new JFrame();
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setSize(100, 80);
          f.setLocation(50, 100);
          f.getContentPane().setLayout(new BorderLayout());

          JButton help = new JButton("Help");
          help.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    JFrame helpFrame = new JFrame();
                    helpFrame.getContentPane().setLayout(new BorderLayout());
                    JEditorPane browser = new JEditorPane();
                    browser.setEditable(false);
                    try {
                         browser.setPage("http://www.experts-exchange.com");
                    } catch (Exception ex) {
                         ex.printStackTrace();
                    }
                    helpFrame.getContentPane().add(new JScrollPane(browser), BorderLayout.CENTER);
                    helpFrame.setSize(500, 500);
                    helpFrame.setLocation(160, 100);
                    helpFrame.setVisible(true);
               }
          });

          f.getContentPane().add(help, BorderLayout.CENTER);
          f.setVisible(true);
     }
}
0
 
objectsCommented:
Yes JEditorPane can be used, but it is pretty limited in it's HTML support.
0
 
OviCommented:
... or if this is not enough you could use JavaHelp.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now