Java Reference
In-Depth Information
Example 10•21: WebBrowser.java (continued)
visit((URL)history.get(--currentHistoryPage));
// Enable or disable actions as appropriate
backAction.setEnabled((currentHistoryPage > 0));
forwardAction.setEnabled((currentHistoryPage < history.size()-1));
}
/** Go forward to the next page in the history list */
public void forward() {
if (currentHistoryPage < history.size()-1) // go forward, if we can
visit((URL)history.get(++currentHistoryPage));
// Enable or disable actions as appropriate
backAction.setEnabled((currentHistoryPage > 0));
forwardAction.setEnabled((currentHistoryPage < history.size()-1));
}
/** Reload the current page in the history list */
public void reload() {
if (currentHistoryPage != -1)
visit((URL)history.get(currentHistoryPage));
}
/** Display the page specified by the "home" property */
public void home() { displayPage(getHome()); }
/** Open a new browser window */
public void newBrowser() {
WebBrowser b = new WebBrowser();
b.setSize(this.getWidth(), this.getHeight());
b.setVisible(true);
}
/**
* Close this browser window. If this was the only open window,
* and exitWhenLastBrowserClosed is true, then exit the VM
**/
public void close() {
this.setVisible(false); // Hide the window
this.dispose(); // Destroy the window
synchronized(WebBrowser.class) { // Synchronize for thread-safety
WebBrowser.numBrowserWindows--; // There is one window fewer now
if ((numBrowserWindows==0) && exitWhenLastWindowClosed)
System.exit(0);
// Exit if it was the last one
}
}
/**
* Exit the VM. If confirm is true, ask the user if they are sure.
* Note that showConfirmDialog() displays a dialog, waits for the user,
* and returns the user's response (i.e. the button the user selected).
**/
public void exit(boolean confirm) {
if (!confirm ||
(JOptionPane.showConfirmDialog(this, // dialog parent
/* message to display */ "Are you sure you want to quit?",
/* dialog title */ "Really Quit?",
/* dialog buttons */ JOptionPane.YES_NO_OPTION) ==
JOptionPane.YES_OPTION)) // If Yes button was clicked
System.exit(0);
Search WWH ::




Custom Search