Java Reference
In-Depth Information
Example 10•21: WebBrowser.java (continued)
toolbar.add(new JLabel("
URL:"));
toolbar.add(urlField);
// And add the toolbar to the top of the window
this.getContentPane().add(toolbar, BorderLayout.NORTH);
// Read cached copies of two Action objects from the resource bundle
// These actions are used by the menubar and toolbar, and enabling and
// disabling them enables and disables the menu and toolbar items.
backAction = (Action)resources.getResource("action.back",Action.class);
forwardAction =
(Action)resources.getResource("action.forward", Action.class);
// Start off with both actions disabled
backAction.setEnabled(false);
forwardAction.setEnabled(false);
// Create a ThemeManager for this frame,
// and add a Theme menu to the menubar
ThemeManager themes = new ThemeManager(this, resources);
menubar.add(themes.getThemeMenu());
// Keep track of how many web browser windows are open
WebBrowser.numBrowserWindows++;
}
/** Set the static property that controls the behavior of close() */
public static void setExitWhenLastWindowClosed(boolean b) {
exitWhenLastWindowClosed = b;
}
/** These are accessor methods for the home property. */
public void setHome(String home) { this.home = home; }
public String getHome() { return home; }
/**
* This internal method attempts to load and display the specified URL.
* It is called from various places throughout the class.
**/
boolean visit(URL url) {
try {
String href = url.toString();
// Start animating. Animation is stopped in propertyChanged()
startAnimation("Loading " + href + "...");
textPane.setPage(url); // Load and display the URL
this.setTitle(href); // Display URL in window titlebar
urlField.setText(href); // Display URL in text input field
return true;
// Return success
}
catch (IOException ex) {
// If page loading fails
stopAnimation();
messageLine.setText("Can't load page: " + ex.getMessage());
return false;
// Return failure
}
}
/**
* Ask the browser to display the specified URL, and put it in the
Search WWH ::




Custom Search