I have a program for which I am designing a help menu. The program allows you to add squares, ovals, and other shapes, and move them, rotate them, etc. I'm setting up some HTML pages that explain how to do different tasks. So when the user pulls down the help menu, I'd like something like this to display in a JFrame:
How do you add a shape?
How do you move a shape?
How do you rotate a shape?
The links above don't lead anywhere from Daniweb, but if you hover over them, you'll notice that they will link to HTML files on the local machine. I'd like the user to be able to click on them, then when they are clicked, a browser opens up with the appropriate help page. At this point, help should be separate from the Java program. The Java program should provide the initial options, then when one is chosen, the browser takes over and is independent of the program.
Currently my first attempt is to use a JEditorPane. Click a button and either Yahoo or Google comes up. I'd like to have a browser come up instead of using the JEditorPane. Second, I'd like to use links like above rather than JButtons as I currently have it, but I don't know how to make text clickable. Can anyone steer me in the right direction? Thanks.
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.*;
import javax.swing.event.*;
public class HelpMain extends JFrame implements ActionListener, HyperlinkListener
{
JPanel panel1;
JPanel panel2;
JEditorPane pane;
JButton googleButton;
JButton yahooButton;
public static void main (String args[])
{
new HelpMain ();
}
public HelpMain ()
{
panel1 = new JPanel ();
panel2 = new JPanel ();
LayoutManager lm = new GridLayout (2,1);
setLayout(lm);
panel1.setBackground(Color.GREEN);
googleButton = new JButton ("Google");
yahooButton = new JButton ("Yahoo");
googleButton.addActionListener(this);
yahooButton.addActionListener (this);
panel1.add (googleButton);
panel1.add (yahooButton);
panel2.setBackground(Color.CYAN);
pane = new JEditorPane ();
pane.setEditable(false);
pane.addHyperlinkListener(this);
panel2.add (pane);
add (panel1);
add (panel2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1000, 600);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource () == googleButton)
{
setHTMLPage ("http://www.google.com");
}
else if (e.getSource () == yahooButton)
{
setHTMLPage ("http://www.yahoo.com");
}
}
public void setHTMLPage (String page)
{
try
{
pane.setPage(page);
}
catch (IOException ex)
{
System.out.println ("Problem setting page.");
}
}
public void hyperlinkUpdate(HyperlinkEvent he)
{
System.out.println ("In Hyperlink Listener");
if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
try
{
pane.setPage(he.getURL());
}
catch(Exception ex)
{
System.out.println ("Problem following link.");
}
}
}
}