Browser Mark Two

Mark One of the primitive WWW browser is described here. Here are links to the files for Mark Two:

The sole purpose of the new version is not to rival Communicator or Internet Explorer or ..., but to show another use of Box, BoxLayout, List and ArrayList. So the new version has buttons for Exit, History and Print. It uses two Boxes for these buttons (including some horizontal glue!). And to implement the History mechanism it uses List and ArrayList.

To keep things reasonably simple, its History mechanism is a little weird. When you click on the History button, it displays, in the main pane, a numbered table of the URLs that have recently been visited. (You may recall that the simple Browser has a JTextField into which you can type a URL.) If instead, you type one of these numbers into the JTextField, it will go to the URL associated with that number. If instead you type a number preceded by a minus sign it will remove the URL from the list.

The file has been extensively modified in order to include the Exit, History and Print buttons and their listeners. To implement the Exit button, the ExitOnWindowClosing class has been modified so that it implements the ActionListener interface as well as the WindowListener interface. And, the PagesHandler class has also been extensively revised in order to build a history of the pages that have been visited. It has:

   private List iHistory;
   iHistory = new ArrayList();
and the code of the PagesHandler class uses the methods iterator, add, get, remove and contains from the List interface.

The JEditorPanePrinter class is a new class: it shows that printing can be done from a Java program. However, the technique used in the program is not recommended as it generates enormous PostScript files. So if you click on the Print button, cancel you printing on the next screen. And please don't put similar code into your programs, and (before you ask) I don't know of any other way at the present.

The HTMLListener class and the URLJTextFieldListener class have not been altered.