2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.demo.impl;
\r
8 import java.applet.Applet;
\r
9 import java.applet.AppletContext;
\r
10 import java.applet.AppletStub;
\r
11 import java.applet.AudioClip;
\r
12 import java.awt.Frame;
\r
13 import java.awt.Image;
\r
14 import java.awt.event.WindowAdapter;
\r
15 import java.awt.event.WindowEvent;
\r
16 import java.io.IOException;
\r
17 import java.io.InputStream;
\r
18 import java.net.URL;
\r
19 import java.util.Enumeration;
\r
20 import java.util.Iterator;
\r
23 * <p>A Frame that runs an Applet within itself, making it possible
\r
24 * for an applet to run as an application. Usage:
\r
27 * public class MyApplet extends Applet {
\r
28 * public static void main(String args[]) {
\r
29 * MyApplet applet = new MyApplet();
\r
30 * new AppletFrame("My Applet Running As An App", applet, 640, 480);
\r
38 public class AppletFrame extends Frame implements AppletStub, AppletContext {
\r
43 private static final long serialVersionUID = 818828281190757725L;
\r
47 * Construct a Frame running the given Applet with the default size
\r
49 * When the Frame is closed, the applet's stop() method is called,
\r
50 * the Frame is dispose()d of, and System.exit(0) is called.
\r
52 * @param name the Frame title
\r
53 * @param applet the applet to be run
\r
55 public AppletFrame(String name, Applet applet) {
\r
56 this(name, applet, 640, 480);
\r
60 * Construct a Frame running the given Applet with the given size.
\r
61 * When the Frame is closed, the applet's stop() method is called,
\r
62 * the Frame is dispose()d of, and System.exit(0) is called.
\r
64 * @param name the Frame title
\r
65 * @param applet the applet to be run
\r
66 * @param width width of the Frame
\r
67 * @param height height of the Frame
\r
69 public AppletFrame(String name, Applet applet, int width, int height) {
\r
71 this.applet = applet;
\r
72 applet.setStub(this);
\r
74 setSize(width, height);
\r
75 add("Center", applet);
\r
77 addWindowListener(new WindowAdapter() {
\r
78 public void windowClosing(WindowEvent e) {
\r
79 AppletFrame.this.applet.stop();
\r
90 public void appletResize(int width, int height) {
\r
91 setSize(width, height);
\r
94 public AppletContext getAppletContext() {
\r
98 public URL getCodeBase() {
\r
102 public URL getDocumentBase() {
\r
106 public String getParameter(String name) {
\r
107 return "PARAMETER";
\r
110 public boolean isActive() {
\r
115 // AppletContext API
\r
116 public Applet getApplet(String name) {
\r
120 public Enumeration getApplets() {
\r
124 public AudioClip getAudioClip(URL url) {
\r
128 public Image getImage(URL url) {
\r
132 public void showDocument(URL url) {}
\r
133 public void showDocument(URL url, String target) {}
\r
135 public void showStatus(String status) {
\r
136 System.out.println(status);
\r
139 public void setStream(String key, InputStream stream) throws IOException {
\r
142 public InputStream getStream(String key) {
\r
146 public Iterator getStreamKeys() {
\r