Java Reference
In-Depth Information
Example 10•21: WebBrowser.java (continued)
import javax.swing.event.*; // Swing event handlers
import java.beans.*; // JavaBeans event handlers
import java.awt.print.*; // Printing functionality
import java.io.*; // Input/output
import java.net.*; // Networking with URLs
import java.util.*; // Hashtables and other utilities
// Import this class by name. JFileChooser uses it, and its name conflicts
// with java.io.FileFilter
import javax.swing.filechooser.FileFilter;
// Import a class for printing Swing documents. See printing chapter.
import com.davidflanagan.examples.print.PrintableDocument;
/**
* This class implements a simple web browser using the HTML
* display capabilities of the JEditorPane component.
**/
public class WebBrowser extends JFrame
implements HyperlinkListener, PropertyChangeListener
{
/**
* A simple main() method that allows the WebBrowser class to be used
* as a stand-alone application.
**/
public static void main(String[] args) throws IOException {
// End the program when there are no more open browser windows
WebBrowser.setExitWhenLastWindowClosed(true);
WebBrowser browser = new WebBrowser(); // Create a browser window
browser.setSize(800, 600);
// Set its size
browser.setVisible(true);
// Make it visible.
// Tell the browser what to display. This method is defined below.
browser.displayPage((args.length > 0) ? args[0] : browser.getHome());
}
// This class uses GUIResourceBundle to create its menubar and toolbar
// This static initializer performs one-time registration of the
// required ResourceParser classes.
static {
GUIResourceBundle.registerResourceParser(new MenuBarParser());
GUIResourceBundle.registerResourceParser(new MenuParser());
GUIResourceBundle.registerResourceParser(new ActionParser());
GUIResourceBundle.registerResourceParser(new CommandParser());
GUIResourceBundle.registerResourceParser(new ToolBarParser());
}
// These are the Swing components that the browser uses
JEditorPane textPane; // Where the HTML is displayed
JLabel messageLine; // Displays one-line messages
JTextField urlField; // Displays and edits the current URL
JFileChooser fileChooser; // Allows the user to select a local file
// These are Actions that are used in the menubar and toolbar.
// We obtain explicit references to them from the GUIResourceBundle
// so we can enable and disable them.
Action backAction, forwardAction;
// These fields are used to maintain the browsing history of the window
java.util.List history = new ArrayList(); // The history list
Search WWH ::




Custom Search