]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/demos/src/com/ibm/icu/dev/demo/impl/AppletFrame.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / demos / src / com / ibm / icu / dev / demo / impl / AppletFrame.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1996-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\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
21 \r
22 /**\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
25  *\r
26  * <pre>\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
31  *     }\r
32  *     ...\r
33  * }\r
34  * <pre>\r
35  *\r
36  * @author Alan Liu\r
37  */\r
38 public class AppletFrame extends Frame implements AppletStub, AppletContext {\r
39 \r
40     /**\r
41      * For serialization\r
42      */\r
43     private static final long serialVersionUID = 818828281190757725L;\r
44     Applet applet;\r
45 \r
46     /**\r
47      * Construct a Frame running the given Applet with the default size\r
48      * of 640 by 480.\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
51      *\r
52      * @param name the Frame title\r
53      * @param applet the applet to be run\r
54      */\r
55     public AppletFrame(String name, Applet applet) {\r
56         this(name, applet, 640, 480);\r
57     }\r
58 \r
59     /**\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
63      *\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
68      */\r
69     public AppletFrame(String name, Applet applet, int width, int height) {\r
70         super(name);\r
71         this.applet = applet;\r
72         applet.setStub(this);\r
73 \r
74         setSize(width, height);\r
75         add("Center", applet);\r
76         show();\r
77         addWindowListener(new WindowAdapter() {\r
78             public void windowClosing(WindowEvent e) {\r
79                 AppletFrame.this.applet.stop();\r
80                 dispose();\r
81                 System.exit(0);\r
82             }\r
83         });\r
84 \r
85         applet.init();\r
86         applet.start();\r
87     }\r
88 \r
89     // AppletStub API\r
90     public void appletResize(int width, int height) {\r
91         setSize(width, height);\r
92     }\r
93 \r
94     public AppletContext getAppletContext() {\r
95         return this;\r
96     }\r
97 \r
98     public URL getCodeBase() {\r
99         return null;\r
100     }\r
101 \r
102     public URL getDocumentBase() {\r
103         return null;\r
104     }\r
105     \r
106     public String getParameter(String name) {\r
107         return "PARAMETER";\r
108     }\r
109 \r
110     public boolean isActive() {\r
111         return true;\r
112     }\r
113     \r
114     \r
115     // AppletContext API\r
116     public Applet getApplet(String name) {\r
117         return applet;\r
118     }\r
119 \r
120     public Enumeration getApplets() {\r
121         return null;\r
122     }\r
123 \r
124     public AudioClip getAudioClip(URL url) {\r
125         return null;\r
126     }\r
127 \r
128     public Image getImage(URL url) {\r
129         return null;\r
130     }\r
131 \r
132     public void showDocument(URL url) {}\r
133     public void showDocument(URL url, String target) {}\r
134 \r
135     public void showStatus(String status) {\r
136         System.out.println(status);\r
137     }\r
138     \r
139     public void setStream(String key, InputStream stream) throws IOException {\r
140     }\r
141     \r
142     public InputStream getStream(String key) {\r
143         return null;\r
144     }\r
145     \r
146     public Iterator getStreamKeys() {\r
147         return null;\r
148     }\r
149 }\r