Java Reference
In-Depth Information
Example 10•21: WebBrowser.java (continued)
int currentHistoryPage = -1; // Current location in it
public static final int MAX_HISTORY = 50; // Trim list when over this size
// These static fields control the behavior of the close() action
static int numBrowserWindows = 0;
static boolean exitWhenLastWindowClosed = false;
// This is where the "home()" method takes us. See also setHome()
String home = "http://www.davidflanagan.com"; // A default value
/** Create and initialize a new WebBrowser window */
public WebBrowser() {
super();
// Chain to JFrame constructor
textPane = new JEditorPane();
// Create HTML window
textPane.setEditable(false);
// Don't allow the user to edit it
// Register action listeners. The first is to handle hyperlinks.
// The second is to receive property change notifications, which tell
// us when a document is done loading. This class implements these
// EventListener interfaces, and the methods are defined below
textPane.addHyperlinkListener(this);
textPane.addPropertyChangeListener(this);
// Put the text pane in a JScrollPane in the center of the window
this.getContentPane().add(new JScrollPane(textPane),
BorderLayout.CENTER);
// Now create a message line and place it at the bottom of the window
messageLine = new JLabel(" ");
this.getContentPane().add(messageLine, BorderLayout.SOUTH);
// Read the file WebBrowserResources.properties (and any localized
// variants appropriate for the current Locale) to create a
// GUIResourceBundle from which we'll get our menubar and toolbar.
GUIResourceBundle resources =
new GUIResourceBundle(this,"com.davidflanagan.examples.gui." +
"WebBrowserResources");
// Read a menubar from the resource bundle and display it
JMenuBar menubar = (JMenuBar) resources.getResource("menubar",
JMenuBar.class);
this.setJMenuBar(menubar);
// Read a toolbar from the resource bundle. Don't display it yet.
JToolBar toolbar =
(JToolBar) resources.getResource("toolbar", JToolBar.class);
// Create a text field that the user can enter a URL in.
// Set up an action listener to respond to the ENTER key in that field
urlField = new JTextField();
urlField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayPage(urlField.getText());
}
});
// Add the URL field and a label for it to the end of the toolbar
Search WWH ::




Custom Search