source: trunk/src/gcc/libjava/java/applet/Applet.java@ 1213

Last change on this file since 1213 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.4 KB
Line 
1/* Applet.java -- Java base applet class
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.applet;
40
41import java.awt.Dimension;
42import java.awt.Image;
43import java.net.URL;
44import java.util.Locale;
45
46/**
47 * This is the base applet class. An applet is a Java program that
48 * runs inside a web browser or other applet viewer in a restricted
49 * environment.
50 *
51 * @author Aaron M. Renn ([email protected])
52 */
53public class Applet extends java.awt.Panel implements java.io.Serializable
54{
55 // The applet stub for this applet
56 private AppletStub stub;
57
58 /**
59 * Default constructor for subclasses.
60 */
61 public Applet() {}
62
63 /**
64 * Returns the URL of the document this applet is embedded in.
65 *
66 * @return The URL of the document this applet is embedded in.
67 */
68 public URL getDocumentBase()
69 {
70 return (stub.getDocumentBase ());
71 }
72
73 /**
74 * Returns the URL of the code base for this applet.
75 *
76 * @return The URL of the code base for this applet.
77 */
78 public URL getCodeBase()
79 {
80 return (stub.getCodeBase ());
81 }
82
83 /**
84 * Returns the value of the specified parameter that was specified in
85 * the <APPLET> tag for this applet.
86 *
87 * @param name The parameter name.
88 *
89 * @param value The parameter value, or <code>null</code> if the parameter
90 * does not exist.
91 */
92 public String getParameter(String name)
93 {
94 return (stub.getParameter (name));
95 }
96
97 /**
98 * Returns the applet context for this applet.
99 *
100 * @return The applet context for this applet.
101 */
102 public AppletContext getAppletContext()
103 {
104 return (stub.getAppletContext ());
105 }
106
107 /**
108 * Tests whether or not this applet is currently active.
109 *
110 * @return <code>true</code> if this applet is active, <code>false</code>
111 * otherwise.
112 */
113 public boolean isActive()
114 {
115 return (stub.isActive ());
116 }
117
118 /**
119 * Requests that the applet window for this applet be resized.
120 *
121 * @param width The new width in pixels.
122 * @param height The new height in pixels.
123 */
124 public void resize(int width, int height)
125 {
126 stub.appletResize (width, height);
127 }
128
129 /**
130 * Requests that the applet window for this applet be resized.
131 *
132 * @param dim The <code>Dimension</code> object with the requested
133 * width and height.
134 */
135 public void resize(Dimension dim)
136 {
137 resize (dim.width, dim.height);
138 }
139
140 /**
141 * Returns an audio clip from the specified URL.
142 *
143 * @param url The URL of the audio clip.
144 *
145 * @return The retrieved audio clip.
146 */
147 public AudioClip getAudioClip(URL url)
148 {
149 return (getAppletContext ().getAudioClip (url));
150 }
151
152 /**
153 * Returns an audio clip from the specified URL and name
154 *
155 * @param url The base URL of the audio clip.
156 * @param name The name of the clip relative to the URL.
157 *
158 * @return The retrieved audio clip.
159 */
160 public AudioClip getAudioClip(URL url, String name)
161 {
162 try
163 {
164 return (getAppletContext ().getAudioClip (new URL (url.toExternalForm()
165 + name)));
166 }
167 catch(Exception e)
168 {
169 return (getAudioClip (url));
170 }
171 }
172
173 /**
174 * Loads and plays the audio clip pointed to by the specified URL.
175 *
176 * @param The URL of the audio clip.
177 */
178 public void play (URL url)
179 {
180 getAudioClip (url).play ();
181 }
182
183 /**
184 * Loads and plays the audio clip pointed to by the specified URL.
185 *
186 * @param The base URL of the audio clip.
187 * @param name The name of the audio clip relative to the URL.
188 */
189 public void play (URL url, String name)
190 {
191 getAudioClip (url, name).play ();
192 }
193
194 /**
195 * Returns an image from the specified URL. Note that the image is not
196 * actually retrieved until the applet attempts to display it, so this
197 * method returns immediately.
198 *
199 * @param url The URL of the image.
200 *
201 * @return The retrieved image.
202 */
203 public Image getImage(URL url)
204 {
205 return (getAppletContext ().getImage (url));
206 }
207
208 /**
209 * Returns an image from the specified URL. Note that the image is not
210 * actually retrieved until the applet attempts to display it, so this
211 * method returns immediately.
212 *
213 * @param url The base URL of the image.
214 * @param name The name of the image relative to the URL.
215 *
216 * @return The retrieved image.
217 */
218 public Image getImage(URL url, String name)
219 {
220 try
221 {
222 return (getAppletContext ().getImage (new URL (url.toExternalForm()
223 + name)));
224 }
225 catch(Exception e)
226 {
227 return (getImage (url));
228 }
229 }
230
231 /**
232 * Returns the locale for this applet, if it has been set. If no applet
233 * specific locale has been set, the default locale is returned.
234 *
235 * @return The locale for this applet.
236 */
237 public Locale getLocale()
238 {
239 return (super.getLocale ());
240 }
241
242 /**
243 * Returns a descriptive string with applet defined information. The
244 * implementation in this class returns <code>null</code>. Applets who
245 * wish to return this information should override.
246 *
247 * @return A string describing the applet.
248 */
249 public String getAppletInfo()
250 {
251 return (null);
252 }
253
254 /**
255 * Returns a list of parameters this applet supports. Each element of
256 * the array is a list of three strings with the name of the parameter,
257 * the data type or valid values, and a description. This method is
258 * optional and the default implementation returns <code>null</code>.
259 *
260 * @return The list of parameters supported by this applet.
261 */
262 public String[][] getParameterInfo()
263 {
264 return (null);
265 }
266
267 /**
268 * This method is called when the applet is first loaded. The default
269 * implementation does nothing. Applets that wish to do one time
270 * initialization should override.
271 */
272 public void init() {}
273
274 /**
275 * This method is called when the applet is being unloaded. The default
276 * implementation does nothing. Applets that need to clean up resources
277 * on exit should override.
278 */
279 public void destroy() {}
280
281 /**
282 * This method is called when the applet should start running. This is
283 * normally each time a web page containing it is loaded. The default
284 * implemention does nothing. Subclasses should override.
285 */
286 public void start() {}
287
288 /**
289 * This method is called when the applet should stop running. This is
290 * normally when the next web page is loaded. The default implementation
291 * does nothing.
292 */
293 public void stop() {}
294
295 /**
296 * The browser calls this method to set the applet's stub, which is the
297 * low level interface to the browser.
298 *
299 * @param stub The applet stub for this applet.
300 */
301 public final void setStub (AppletStub stub)
302 {
303 this.stub = stub;
304 }
305
306} // class Applet
307
Note: See TracBrowser for help on using the repository browser.