001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.dev.demo.impl;
008:
009: import java.applet.*;
010: import java.net.URL;
011: import java.util.Enumeration;
012: import java.util.Iterator;
013: import java.awt.*;
014: import java.awt.event.*;
015: import java.io.InputStream;
016: import java.io.IOException;
017:
018: /**
019: * <p>A Frame that runs an Applet within itself, making it possible
020: * for an applet to run as an application. Usage:
021: *
022: * <pre>
023: * public class MyApplet extends Applet {
024: * public static void main(String args[]) {
025: * MyApplet applet = new MyApplet();
026: * new AppletFrame("My Applet Running As An App", applet, 640, 480);
027: * }
028: * ...
029: * }
030: * <pre>
031: *
032: * <p>Copyright © IBM Corporation 1999. All rights reserved.
033: *
034: * @author Alan Liu
035: */
036: public class AppletFrame extends Frame implements AppletStub,
037: AppletContext {
038:
039: Applet applet;
040:
041: private static final String COPYRIGHT = "\u00A9 IBM Corporation 1999. All rights reserved.";
042:
043: /**
044: * Construct a Frame running the given Applet with the default size
045: * of 640 by 480.
046: * When the Frame is closed, the applet's stop() method is called,
047: * the Frame is dispose()d of, and System.exit(0) is called.
048: *
049: * @param name the Frame title
050: * @param applet the applet to be run
051: */
052: public AppletFrame(String name, Applet applet) {
053: this (name, applet, 640, 480);
054: }
055:
056: /**
057: * Construct a Frame running the given Applet with the given size.
058: * When the Frame is closed, the applet's stop() method is called,
059: * the Frame is dispose()d of, and System.exit(0) is called.
060: *
061: * @param name the Frame title
062: * @param applet the applet to be run
063: * @param width width of the Frame
064: * @param height height of the Frame
065: */
066: public AppletFrame(String name, Applet applet, int width, int height) {
067: super (name);
068: this .applet = applet;
069: applet.setStub(this );
070:
071: setSize(width, height);
072: add("Center", applet);
073: show();
074: addWindowListener(new WindowAdapter() {
075: public void windowClosing(WindowEvent e) {
076: AppletFrame.this .applet.stop();
077: dispose();
078: System.exit(0);
079: }
080: });
081:
082: applet.init();
083: applet.start();
084: }
085:
086: // AppletStub API
087: public void appletResize(int width, int height) {
088: setSize(width, height);
089: }
090:
091: public AppletContext getAppletContext() {
092: return this ;
093: }
094:
095: public URL getCodeBase() {
096: return null;
097: }
098:
099: public URL getDocumentBase() {
100: return null;
101: }
102:
103: public String getParameter(String name) {
104: return "PARAMETER";
105: }
106:
107: public boolean isActive() {
108: return true;
109: }
110:
111: // AppletContext API
112: public Applet getApplet(String name) {
113: return applet;
114: }
115:
116: public Enumeration getApplets() {
117: return null;
118: }
119:
120: public AudioClip getAudioClip(URL url) {
121: return null;
122: }
123:
124: public Image getImage(URL url) {
125: return null;
126: }
127:
128: public void showDocument(URL url) {
129: }
130:
131: public void showDocument(URL url, String target) {
132: }
133:
134: public void showStatus(String status) {
135: System.out.println(status);
136: }
137:
138: public void setStream(String key, InputStream stream)
139: throws IOException {
140: }
141:
142: public InputStream getStream(String key) {
143: return null;
144: }
145:
146: public Iterator getStreamKeys() {
147: return null;
148: }
149: }
|