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!

Having trouble with Java web browser

Status
Not open for further replies.

Cybertronic

Technical User
May 18, 2006
19
Hi all,

I apologise for creating another thread but I would love to have some help with my problem I'm currently having please.

I've created a web browser in Java where I have several different classes to help separate the code for ease of coding. I'm currently stuck on a Java class issue where I trying to code the backwards and forwards buttons in my browser.

I've got the HyperlinkHandler class below:

Code:
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.io.IOException;

public class HyperlinkHandler implements HyperlinkListener
{
  JEditorPane contentPane;
  JToolBar toolBar;

  public void hyperlinkUpdate(HyperlinkEvent event)
  {
//    String address = addressTextField.getText();

    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    {
      [b]ToolBar.historyResize("" + event.getURL());[/b]
//      toolBar.showURL("" + event.getURL());

      try
      {
        contentPane = (JEditorPane) event.getSource();
        contentPane.setPage(event.getURL());
//        toolBar.addressTextField.setText(event.getURL().toExternalForm());
      }
      catch (IOException ioe)
      {
        JOptionPane.showMessageDialog(null,
                "Java Web Browser can't find the server at " + ioe,
                "Java Web Browser",
                JOptionPane.ERROR_MESSAGE);
      }
    }
  }

and the historyResize method in a class called ToolBar:

Code:
private void historyResize(String url)
{
  historyActive++;

  history[historyActive] = url;
  historySize = historyActive + 1;
  if (historySize == historyMax)
  {
    historyMax += 10;
    String temp[] = new String[historyMax];
    for (int i = 0; i < historySize; i++)
    {
      temp[i] = history[i];
    }
    history = temp;
  }
  buttonCheck();
}

The bold line of code in the HyperlinkHandler class above is currently giving me problems where my Java software comes up with an error saying:

historyResize(java.lang.String) has private access in ToolBar

If I change private to public it'll then say the following:

Non-static method historyResize(java.lang.String) cannot be referenced from a static context

If I include static in the historyResize method, some of my variables within that method will come up with a similar error as above :(

After trying those, I tried declaring an instance of the ToolBar class in the HyperlinkHandler class:

ToolBar toolBar = new ToolBar(contentPane, browserPanel);

This compiles fine but if I try to click on a link I get "java.lang.NullPointerException" errors :(

I'm really lost here and can anybody please help me?

I appreciate anybody's help :)
 
I think you want :

toolBar.historyResize("" + event.getURL());

rather than :

ToolBar.historyResize("" + event.getURL());

As for the NullPointerException - you probably have not initialized your "history" array, or some other object.

Just add debug to your code, or step through it in your IDE until you see the line with the problem.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top