// A program that is a simple WWW browser. // Barry Cornelius, 13th February 2000 import java.awt. BorderLayout; import javax.swing. Box; import javax.swing. BoxLayout; import java.awt. Container; import java.io. IOException; import javax.swing. JButton; import javax.swing. JEditorPane; import javax.swing. JFrame; import javax.swing. JScrollPane; import javax.swing. JTextField; import java.util. Properties; public class Browser { public static void main(final String[] pArgs) { // you will need to uncomment the following three statements // if your access to the WWW is through a proxy machine // you will have to replace proxymachine.sitename.com // and 8080 with appropriate values for your site // final Properties tProperties = System.getProperties(); // tProperties.put("http.proxyHost", "proxymachine.sitename.com"); // tProperties.put("http.proxyPort", "8080"); final String tFirstURLString = "http://www.dur.ac.uk/understanding.java/"; final JButton tExitButton = new JButton("Exit"); final JButton tHistoryButton = new JButton("History"); final JButton tPrintButton = new JButton("Print"); final JEditorPane tJEditorPane = new JEditorPane(); tJEditorPane.setContentType("text/html"); tJEditorPane.setEditable(false); final JTextField tStatusJTextField = new JTextField(""); final JTextField tURLJTextField = new JTextField(tFirstURLString); final PagesHandler tPagesHandler = new PagesHandler(tJEditorPane, tURLJTextField); final URLJTextFieldListener tURLJTextFieldListener = new URLJTextFieldListener(tPagesHandler, tURLJTextField); final HTMLListener tHTMLListener = new HTMLListener(tPagesHandler, tStatusJTextField); final JEditorPanePrinter tJEditorPanePrinter = new JEditorPanePrinter(tJEditorPane); final Box tButtonsBox = new Box(BoxLayout.X_AXIS); tButtonsBox.add(tExitButton); tButtonsBox.add(tHistoryButton); tButtonsBox.add(tPrintButton); tButtonsBox.add(Box.createHorizontalGlue()); final Box tNorthBox = new Box(BoxLayout.Y_AXIS); tNorthBox.add(tButtonsBox); tNorthBox.add(tURLJTextField); final JFrame tJFrame = new JFrame("Browser"); final ExitOnWindowClosing tExitOnWindowClosing = new ExitOnWindowClosing(tJFrame); tJFrame.addWindowListener(tExitOnWindowClosing); tExitButton.addActionListener(tExitOnWindowClosing); tHistoryButton.addActionListener(tPagesHandler); tPrintButton.addActionListener(tJEditorPanePrinter); tJEditorPane.addHyperlinkListener(tHTMLListener); tURLJTextField.addActionListener(tURLJTextFieldListener); final JScrollPane tJScrollPane = new JScrollPane(tJEditorPane); final Container tContentPane = tJFrame.getContentPane(); tContentPane.add(tNorthBox, BorderLayout.NORTH); tContentPane.add(tJScrollPane, BorderLayout.CENTER); tContentPane.add(tStatusJTextField, BorderLayout.SOUTH); tJFrame.setLocation(100, 100); tJFrame.setSize(800, 500); tJFrame.setVisible(true); tPagesHandler.setPage(tFirstURLString); } }