Debian Codegraph @

demos/src/main/java/com/ibm/icu/dev/demo/impl/AppletFrame.java

raw
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 1996-2010, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
8 */
9 package com.ibm.icu.dev.demo.impl;
10 import java.applet.Applet;
11 import java.applet.AppletContext;
12 import java.applet.AppletStub;
13 import java.applet.AudioClip;
14 import java.awt.Frame;
15 import java.awt.Image;
16 import java.awt.event.WindowAdapter;
17 import java.awt.event.WindowEvent;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.net.URL;
21 import java.util.Enumeration;
22 import java.util.Iterator;
23
24 /**
25 * <p>A Frame that runs an Applet within itself, making it possible
26 * for an applet to run as an application. Usage:
27 *
28 * <pre>
29 * public class MyApplet extends Applet {
30 * public static void main(String args[]) {
31 * MyApplet applet = new MyApplet();
32 * new AppletFrame("My Applet Running As An App", applet, 640, 480);
33 * }
34 * ...
35 * }
36 * <pre>
37 *
38 * @author Alan Liu
39 */
40 public class AppletFrame extends Frame implements AppletStub, AppletContext {
41
42 /**
43 * For serialization
44 */
45 private static final long serialVersionUID = 818828281190757725L;
46 Applet applet;
47
48 /**
49 * Construct a Frame running the given Applet with the default size
50 * of 640 by 480.
51 * When the Frame is closed, the applet's stop() method is called,
52 * the Frame is dispose()d of, and System.exit(0) is called.
53 *
54 * @param name the Frame title
55 * @param applet the applet to be run
56 */
57 public AppletFrame(String name, Applet applet) {
58 this(name, applet, 640, 480);
59 }
60
61 /**
62 * Construct a Frame running the given Applet with the given size.
63 * When the Frame is closed, the applet's stop() method is called,
64 * the Frame is dispose()d of, and System.exit(0) is called.
65 *
66 * @param name the Frame title
67 * @param applet the applet to be run
68 * @param width width of the Frame
69 * @param height height of the Frame
70 */
71 public AppletFrame(String name, Applet applet, int width, int height) {
72 super(name);
73 this.applet = applet;
74 applet.setStub(this);
75
76 setSize(width, height);
77 add("Center", applet);
78 show();
79 addWindowListener(new WindowAdapter() {
80 public void windowClosing(WindowEvent e) {
81 AppletFrame.this.applet.stop();
82 dispose();
83 System.exit(0);
84 }
85 });
86
87 applet.init();
88 applet.start();
89 }
90
91 // AppletStub API
92 public void appletResize(int width, int height) {
93 setSize(width, height);
94 }
95
96 public AppletContext getAppletContext() {
97 return this;
98 }
99
100 public URL getCodeBase() {
101 return null;
102 }
103
104 public URL getDocumentBase() {
105 return null;
106 }
107
108 public String getParameter(String name) {
109 return "PARAMETER";
110 }
111
112 public boolean isActive() {
113 return true;
114 }
115
116
117 // AppletContext API
118 public Applet getApplet(String name) {
119 return applet;
120 }
121
122 public Enumeration getApplets() {
123 return null;
124 }
125
126 public AudioClip getAudioClip(URL url) {
127 return null;
128 }
129
130 public Image getImage(URL url) {
131 return null;
132 }
133
134 public void showDocument(URL url) {}
135 public void showDocument(URL url, String target) {}
136
137 public void showStatus(String status) {
138 System.out.println(status);
139 }
140
141 public void setStream(String key, InputStream stream) throws IOException {
142 }
143
144 public InputStream getStream(String key) {
145 return null;
146 }
147
148 public Iterator getStreamKeys() {
149 return null;
150 }
151 }