Browser Questions


The code giveni shows how easy it is to create a web browser in Java and how easy it is to write poorly designed GUI programs. Your task is to understand, modify, and ultimately re-design this program to support many features of modern web browsers such as history, bookmarks, mulitple tabs, search, RSS feeds, etc.

Understanding

  1. The private method showPage is called from two places in the Browser class, how are these calls triggered?
  2. Where should the code go to add a "go" button to load a URL, that does the same thing as pressing return in the url/address textbox does.

    What will the added code be? How will the URL/string be obtained (why is this different from how it's obtained from pressing return in the textfield?)

  3. The private class LinkFollower processes link clicks in the browser. In its method hyperLinkUpdate the code below appears. Why is the call to showNextURL, which is in the Browser class, valid? try { showNextURL(evt.getURL().toString()); } catch (Exception e) { // nothing to do, if URL fails, don't pre-announce }

    If the call is replaced with this.showNextURL the compiler generates this message:

    Browser.java:217: cannot resolve symbol symbol : method showNextURL (java.lang.String) location: class Browser.LinkFollower this.showNextURL(evt.getURL().toString()); ^ 1 error Compilation exited abnormally with code 1 at Tue Mar 18 10:08:46 Explain why this is an error. If this is replaced by Browser.this there is no error, the code is fine. Explain

Modifications

  1. The Back and Next buttons are very far apart. This is, arguably, a bad choice from a UI-perspective. If the panel the buttons are in is replaced by one with the default FlowLayout, using this code: (see makeButtons where the code below replaces the BorderLayout panel at the end of the function). JPanel panel = new JPanel(); panel.add(myBackButton); panel.add(myNextButton); then the resulting window looks like this:

    backnext in middle

    Propose a simple solution to keep the buttons together, but at the left of the bar rather than in the middle.

  2. You are to add a new Menu, whose title is Go, which contains options for next, back, and home (the latter option won't do anything now, the next and back menu choices should mirror what the buttons do). Where should this code go? What will the code look like?
  3. Make the back/next buttons functional. What does this mean? What are the different use-cases scenarios to think about in terms of button functionality?

    How will you implement next/back? What state needs to be kept in the browser? Are there other features regarding visited URLs that you could add using this state?