![]() ![]() ![]() ![]() |
Communicating with Other Programs |
Many of the Applet and AppletContext methods involve some sort of communication with the browser or applet viewer. For example, the AppletgetDocumentBase()
andgetCodeBase()
methods get information from the browser or applet viewer about where the applet and its HTML page came from. The AppletshowStatus()
method tells the browser or viewer to display a status message. The AppletgetParameterInfo()
method can give a browser a list of the parameters an applet understands. And, of course, the browser or applet viewer calls the Appletinit
,start
,stop
, anddestroy
methods to inform the applet of changes in its state. All these methods are discussed elsewhere in this trail.Two other interesting methods are the AppletContext
showDocument()
methods. With these methods, an applet can control which URL the browser shows, and in which browser window. (By the way, the Applet Viewer ignores these methods.) Here are the two forms ofshowDocument()
:The one-argument form ofpublic void showDocument(java.net.URL url) public void showDocument(java.net.URL url, String targetWindow)showDocument()
simply tells the browser to display the document at the specified URL, without specifying the window to display the document in.The two-argument form of
showDocument()
specifies which window to display the document in. The second argument can have the following values:Here's an applet that uses both forms of
"_self"
- Display the document in the window that contains the applet.
"_parent"
- Display the document in the parent window of the window that contains the applet. If the applet's window is a top-level window, this acts the same as "_self". [CHECK]
"_top"
- Display the document in the top-level window (Frame) above the dependent window that contains the applet. If the applet's window is a top-level window, this acts the same as "_self". [CHECK]
"_blank"
- Display the document in a new, nameless window.
"windowName"
- Display the document in a window named windowName. This window will be created if necessary.
showDocument()
: [WHY IS THIS APPLET SO FRAGILE -- AT LEAST IN NETSCAPE? It just seems to go south at some point, and then you have to reload the applet to get it to work again.]
Below is the applet code that calls
showDocument()
. (Here's the whole program.)...//In the Applet subclass... urlWindow = new URLWindow(getAppletContext()); . . . class URLWindow extends Frame { . . . public URLWindow(AppletContext appletContext) { . . . this.appletContext = appletContext; . . . } public boolean action(Event event, Object o) { . . . URL url = null; try { url = new URL(urlString); } catch (MalformedURLException e) { ...//Inform the user, somehow, and return... } if (url != null) { if (/* user doesn't want to specify the window */) { appletContext.showDocument(url); } else { appletContext.showDocument(url, /* user's choice */); } } . . .
![]() ![]() ![]() ![]() |
Communicating with Other Programs |