Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JEditorPane web browser problem

Status
Not open for further replies.

Cybertronic

Technical User
May 18, 2006
19
Hi all,

I'm having a problem with my Java web browser program that I'm working on. At the moment I'm stuck on trying to get my web browser to load the home page after it has been executed. Below is my current code for the actionPerformed method:

Code:
public void actionPerformed (ActionEvent ae)
  {
    String address = addressTextField.getText();

    try
    {
      contentPane.setPage(address);
      addressTextField.setText(address);
    }
    catch(IOException ioe)
    {
	    JOptionPane.showMessageDialog(null, "Warning " + address, "Java Web Browser", JOptionPane.ERROR_MESSAGE);
	  }
  }
If I try to change address to a string containing a URL e.g " it doesn't load the website after it has been executed :(

Can anybody please help me? :)

I appreciate anyone's assistance,

Thanks,

Jonathan
 
Yeah, but what does it do? Does it show that error dialog you've put in? If so, you could do with looking into that IOException for a description of the probably cause. If not, then we need more information.

Tim
 
I have the following code (including the the code in my previous post) in my web browser program:

Code:
public class browser extends JFrame implements ActionListener, HyperlinkListener
{
  private JEditorPane contentPane;
  private JScrollPane contentScrollPane;

  // Code for GUI

  public browser()
  {
    // Code for GUI

    contentPane = new JEditorPane();
    contentPane.setEditable(false);
    contentPane.addHyperlinkListener(this);

    contentScrollPane = new JScrollPane(contentPane);
    getContentPane().add(contentScrollPane, BorderLayout.CENTER);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("Java Web Browser");
    setSize(800, 600);
    setVisible(true);
  }

  public void actionPerformed (ActionEvent ae)
  {
    String address = addressTextField.getText();

    try
    {
      contentPane.setPage(address);
      addressTextField.setText(address);
    }
    catch(IOException ioe)
    {
      JOptionPane.showMessageDialog(null, "Warning " + address, "Java Web Browser", JOptionPane.ERROR_MESSAGE);
    }
  }
  public void hyperlinkUpdate(HyperlinkEvent event)
  {
    // Code for hyperlinkUpdate
  }
}

I haven't included the GUI code above yet. It doesn't show anything when I execute the web browser and it doesn't come up with a warning message apart from URLs that don't exist :(
 
What fires the 'actionPerformed' event handler?

Tim
 
Tim, my web browser buttons fires the actionPerformed event handler. I've fixed the problem now, what I had to do was wrap the "contentPane = new JEditorPane();" line in a try and catch block and then put the URL in the JEditorPane brackets and create an error message for websites not supported by JEditorPane.

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top