KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > applet > AppletContext


1 /*
2  * @(#)AppletContext.java 1.31 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.applet;
9
10 import java.awt.Image JavaDoc;
11 import java.awt.Graphics JavaDoc;
12 import java.awt.image.ColorModel JavaDoc;
13 import java.net.URL JavaDoc;
14 import java.util.Enumeration JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 /**
20  * This interface corresponds to an applet's environment: the
21  * document containing the applet and the other applets in the same
22  * document.
23  * <p>
24  * The methods in this interface can be used by an applet to obtain
25  * information about its environment.
26  *
27  * @author Arthur van Hoff
28  * @version 1.31, 05/05/04
29  * @since JDK1.0
30  */

31 public interface AppletContext {
32     /**
33      * Creates an audio clip.
34      *
35      * @param url an absolute URL giving the location of the audio clip.
36      * @return the audio clip at the specified URL.
37      */

38     AudioClip JavaDoc getAudioClip(URL JavaDoc url);
39
40     /**
41      * Returns an <code>Image</code> object that can then be painted on
42      * the screen. The <code>url</code> argument<code> </code>that is
43      * passed as an argument must specify an absolute URL.
44      * <p>
45      * This method always returns immediately, whether or not the image
46      * exists. When the applet attempts to draw the image on the screen,
47      * the data will be loaded. The graphics primitives that draw the
48      * image will incrementally paint on the screen.
49      *
50      * @param url an absolute URL giving the location of the image.
51      * @return the image at the specified URL.
52      * @see java.awt.Image
53      */

54     Image JavaDoc getImage(URL JavaDoc url);
55
56     /**
57      * Finds and returns the applet in the document represented by this
58      * applet context with the given name. The name can be set in the
59      * HTML tag by setting the <code>name</code> attribute.
60      *
61      * @param name an applet name.
62      * @return the applet with the given name, or <code>null</code> if
63      * not found.
64      */

65     Applet JavaDoc getApplet(String JavaDoc name);
66
67     /**
68      * Finds all the applets in the document represented by this applet
69      * context.
70      *
71      * @return an enumeration of all applets in the document represented by
72      * this applet context.
73      */

74     Enumeration JavaDoc<Applet JavaDoc> getApplets();
75
76     /**
77      * Replaces the Web page currently being viewed with the given URL.
78      * This method may be ignored by applet contexts that are not
79      * browsers.
80      *
81      * @param url an absolute URL giving the location of the document.
82      */

83     void showDocument(URL JavaDoc url);
84
85     /**
86      * Requests that the browser or applet viewer show the Web page
87      * indicated by the <code>url</code> argument. The
88      * <code>target</code> argument indicates in which HTML frame the
89      * document is to be displayed.
90      * The target argument is interpreted as follows:
91      * <p>
92      * <center><table border="3" summary="Target arguments and their descriptions">
93      * <tr><th>Target Argument</th><th>Description</th></tr>
94      * <tr><td><code>"_self"</code> <td>Show in the window and frame that
95      * contain the applet.</tr>
96      * <tr><td><code>"_parent"</code><td>Show in the applet's parent frame. If
97      * the applet's frame has no parent frame,
98      * acts the same as "_self".</tr>
99      * <tr><td><code>"_top"</code> <td>Show in the top-level frame of the applet's
100      * window. If the applet's frame is the
101      * top-level frame, acts the same as "_self".</tr>
102      * <tr><td><code>"_blank"</code> <td>Show in a new, unnamed
103      * top-level window.</tr>
104      * <tr><td><i>name</i><td>Show in the frame or window named <i>name</i>. If
105      * a target named <i>name</i> does not already exist, a
106      * new top-level window with the specified name is created,
107      * and the document is shown there.</tr>
108      * </table> </center>
109      * <p>
110      * An applet viewer or browser is free to ignore <code>showDocument</code>.
111      *
112      * @param url an absolute URL giving the location of the document.
113      * @param target a <code>String</code> indicating where to display
114      * the page.
115      */

116     public void showDocument(URL JavaDoc url, String JavaDoc target);
117
118     /**
119      * Requests that the argument string be displayed in the
120      * "status window". Many browsers and applet viewers
121      * provide such a window, where the application can inform users of
122      * its current state.
123      *
124      * @param status a string to display in the status window.
125      */

126     void showStatus(String JavaDoc status);
127
128     /**
129      * Associates the specified stream with the specified key in this
130      * applet context. If the applet context previously contained a mapping
131      * for this key, the old value is replaced.
132      * <p>
133      * For security reasons, mapping of streams and keys exists for each
134      * codebase. In other words, applet from one codebase cannot access
135      * the streams created by an applet from a different codebase
136      * <p>
137      * @param key key with which the specified value is to be associated.
138      * @param stream stream to be associated with the specified key. If this
139      * parameter is <code>null<code>, the specified key is removed
140      * in this applet context.
141      * @throws <code>IOException</code> if the stream size exceeds a certain
142      * size limit. Size limit is decided by the implementor of this
143      * interface.
144      * @since JDK1.4
145      */

146     public void setStream(String JavaDoc key, InputStream JavaDoc stream)throws IOException JavaDoc;
147
148     /**
149      * Returns the stream to which specified key is associated within this
150      * applet context. Returns <tt>null</tt> if the applet context contains
151      * no stream for this key.
152      * <p>
153      * For security reasons, mapping of streams and keys exists for each
154      * codebase. In other words, applet from one codebase cannot access
155      * the streams created by an applet from a different codebase
156      * <p>
157      * @return the stream to which this applet context maps the key
158      * @param key key whose associated stream is to be returned.
159      * @since JDK1.4
160      */

161     public InputStream JavaDoc getStream(String JavaDoc key);
162
163     /**
164      * Finds all the keys of the streams in this applet context.
165      * <p>
166      * For security reasons, mapping of streams and keys exists for each
167      * codebase. In other words, applet from one codebase cannot access
168      * the streams created by an applet from a different codebase
169      * <p>
170      * @return an Iterator of all the names of the streams in this applet
171      * context.
172      * @since JDK1.4
173      */

174     public Iterator JavaDoc<String JavaDoc> getStreamKeys();
175 }
176
Popular Tags