1 7 package java.applet; 8 9 import java.awt.*; 10 import java.awt.image.ColorModel ; 11 import java.io.IOException ; 12 import java.io.ObjectInputStream ; 13 import java.net.URL ; 14 import java.net.MalformedURLException ; 15 import java.util.Hashtable ; 16 import java.util.Locale ; 17 import javax.accessibility.*; 18 19 33 public class Applet extends Panel { 34 35 42 public Applet() throws HeadlessException { 43 if (GraphicsEnvironment.isHeadless()) { 44 throw new HeadlessException(); 45 } 46 } 47 48 59 transient private AppletStub stub; 60 61 62 private static final long serialVersionUID = -5836846270535785031L; 63 64 73 private void readObject(ObjectInputStream s) 74 throws ClassNotFoundException , IOException , HeadlessException { 75 if (GraphicsEnvironment.isHeadless()) { 76 throw new HeadlessException(); 77 } 78 s.defaultReadObject(); 79 } 80 81 90 public final void setStub(AppletStub stub) { 91 if (this.stub != null) { 92 SecurityManager s = System.getSecurityManager(); 93 if (s != null) { 94 s.checkPermission(new AWTPermission("setAppletStub")); 95 } 96 } 97 this.stub = (AppletStub )stub; 98 } 99 100 110 public boolean isActive() { 111 if (stub != null) { 112 return stub.isActive(); 113 } else { return false; 115 } 116 } 117 118 134 public URL getDocumentBase() { 135 return stub.getDocumentBase(); 136 } 137 138 145 public URL getCodeBase() { 146 return stub.getCodeBase(); 147 } 148 149 167 public String getParameter(String name) { 168 return stub.getParameter(name); 169 } 170 171 180 public AppletContext getAppletContext() { 181 return stub.getAppletContext(); 182 } 183 184 190 public void resize(int width, int height) { 191 Dimension d = size(); 192 if ((d.width != width) || (d.height != height)) { 193 super.resize(width, height); 194 if (stub != null) { 195 stub.appletResize(width, height); 196 } 197 } 198 } 199 200 205 public void resize(Dimension d) { 206 resize(d.width, d.height); 207 } 208 209 217 public void showStatus(String msg) { 218 getAppletContext().showStatus(msg); 219 } 220 221 235 public Image getImage(URL url) { 236 return getAppletContext().getImage(url); 237 } 238 239 256 public Image getImage(URL url, String name) { 257 try { 258 return getImage(new URL (url, name)); 259 } catch (MalformedURLException e) { 260 return null; 261 } 262 } 263 264 272 public final static AudioClip newAudioClip(URL url) { 273 return new sun.applet.AppletAudioClip(url); 274 } 275 276 288 public AudioClip getAudioClip(URL url) { 289 return getAppletContext().getAudioClip(url); 290 } 291 292 307 public AudioClip getAudioClip(URL url, String name) { 308 try { 309 return getAudioClip(new URL (url, name)); 310 } catch (MalformedURLException e) { 311 return null; 312 } 313 } 314 315 326 public String getAppletInfo() { 327 return null; 328 } 329 330 338 339 public Locale getLocale() { 340 Locale locale = super.getLocale(); 341 if (locale == null) { 342 return Locale.getDefault(); 343 } 344 return locale; 345 } 346 347 368 public String [][] getParameterInfo() { 369 return null; 370 } 371 372 378 public void play(URL url) { 379 AudioClip clip = getAudioClip(url); 380 if (clip != null) { 381 clip.play(); 382 } 383 } 384 385 394 public void play(URL url, String name) { 395 AudioClip clip = getAudioClip(url, name); 396 if (clip != null) { 397 clip.play(); 398 } 399 } 400 401 419 public void init() { 420 } 421 422 451 public void start() { 452 } 453 454 473 public void stop() { 474 } 475 476 495 public void destroy() { 496 } 497 498 502 AccessibleContext accessibleContext = null; 503 504 513 public AccessibleContext getAccessibleContext() { 514 if (accessibleContext == null) { 515 accessibleContext = new AccessibleApplet(); 516 } 517 return accessibleContext; 518 } 519 520 525 protected class AccessibleApplet extends AccessibleAWTPanel { 526 527 private static final long serialVersionUID = 8127374778187708896L; 528 529 535 public AccessibleRole getAccessibleRole() { 536 return AccessibleRole.FRAME; 537 } 538 539 546 public AccessibleStateSet getAccessibleStateSet() { 547 AccessibleStateSet states = super.getAccessibleStateSet(); 548 states.add(AccessibleState.ACTIVE); 549 return states; 550 } 551 552 } 553 } 554 | Popular Tags |