|
Applicet Framework for Applets and Applications v2.03 | ||||||
| PREV NEXT | FRAMES NO FRAMES | ||||||
See:
Description
| Packages | |
| be.arci.applet | This package contains the Applicet Framework for Applets and Applications; additional helper classes can be found in the be.arci.pub package. |
| be.arci.pub | Supplies some add-on classes and Browser implementations for the Applicet Framework for Applets and Applications, together with their source code. |
| edu.stanford.ejalbert | Contains Eric Albert's BrowserLauncher, which is delegated to from the EricAlbertBrowser implementation of the Browser interface for handling calls to showDocument in an Applicet application's AppletContext. |
The Applicet Framework gives Applicet applications the necessary implementations of the java.applet.AppletStub and java.applet.AppletContext interfaces that are needed to run an applet as application without changing any code, and without having to branch on switches you maintain to distinguish between both execution environments. Additional benefits are uniform support for retrieving resources as Image, AudioClip, URL or Inputstream, even across application environments, Web browsers and packaging options. And last but not least, the Applicet Framework makes internationalization of your applet/application trivial.
Note: In this and other documents we'll say 'Applicet applet' or 'Applicet application' whenever there is a difference between running as an applet and running as an application. But really it is the same program. We will also only make the distinction AWT Applicet versus Swing JApplicet when there is need for it.
The main method in the class that you will use to start as application (probably the Applicet subclass itself), has to instantiate (construct) the Applicet, and invoke runAsApplication() on it, as described below. In fact, we successfully converted many existing applets to applications by just changing the extends clause and adding a single-line main():
import be.arci.applet.*;
|
The method runAsApplication(String[] args) does the same for an Applicet application, as the webbrowser does for an applet. It also reads parameters from the args commandline arguments and from default .properties files, just the same parameters a browser would read from the HTML document containing the same Applicet as applet. You must invoke this method exactly once on the Applicet application instance, preferrably as first method after construction. Typically you will invoke runAsApplication() from the static void main(String[] args) method that you must define to run an application, but you might as well call it from the constructor code itself. Do not ever invoke runAsApplication() from the parameterless constructor of your Applicet subclass, for that constructer is used for as-Applet construction by browsers!
The Applicet class has three different signatures for runAsApplication():
Here are some minimal examples:
import be.arci.applet.*;
|
import be.arci.applet.*;
|
Applicet.Context.showUsage(String sMessage, boolean swExit) or JApplicet.Context.showUsage(String sMessage, boolean swExit)).
myApplicet.getParentFrame().setTitle("myTitle");
Image icon = getImage("myicon.gif");
myApplicet.getParentFrame().setIconImage(icon);
Parameter names in .properties files should have a "param." prefix, to distinguish them from possible other properties (like localized user messages).
Parameter names can be defined in the return value of getParameterInfo(). If they are, Applicet's application stub expands commandline parameter name abbreviations (not those in .properties files) to the full parameter name. If an abbreviation is ambiguous, a usage dialog is displayed and the Applicet application exits.
All attributes of the <APPLET> tag are reserved parameter names (and can also be abbreviated) (also see the HTML APPLET tag description). Of these currently the following are used in Applicet applications:
The NAME = applicetInstanceName attribute is replaced by the String sName argument of runAsApplication, as applet naming serves intra-applet communication, and you wouldn't want users interfere with that. Other parameters supplied to the Applicet application are the equivalent of the <PARM NAME = "" VALUE = ""> tags in an HTML document for the Applicet applet.
Parameter help (see also Applicet.Context.showUsage(String sMessage, boolean swExit) or JApplicet.Context.showUsage(String sMessage, boolean swExit)) is displayed in a Dialog and in the eventual console window if either
Parameter help is not shown when a parameter cannot be matched to a parameter named by the return value of getParameterInfo(); this allows for the use of 'hidden' parameters , as well as for the omission of getParameterInfo() (fie!).
In the current implementation the default parent Frame (or JFrame's contentpane for Swing applicets) has the BorderLayout, with your Applicet at BorderLayout.CENTER and a status field at BorderLayout.SOUTH; don't count on this layout to remain that way though (you have no control over it for an applet in a webbrowser either).
You don't have to change a single line of code for it, and it'll run in Netscape and MS Internet Explorer (locally or from a website), or locally as application (or even with AppletViewer).
The following files have to be included in your package:
| Files to include in distribution | Approx. jarred size |
Applicet applet | Applicet application | Both | ||||
|---|---|---|---|---|---|---|---|---|
| Basic (incl. sound by URL) | Sound by name | I18N | Basic (incl. I18N) | Sound by URL or name | show HTML | Parameter conveniences | ||
| be / arci / applet / Framework.class | 0.3kB | X | X | X | X | X | X | X |
| be / arci / applet / Applicet.class | 3.5kB | X | X | X | X | X | X | X |
| be / arci / applet / HFile.class (some environments do not require this file) |
0.1kB | X | X | X | X | X | X | X |
| be / arci / applet / Applicet_xx.properties | n.a. | - | - | - | X | X | X | X |
| be / arci / applet / AudioClipFactory.class | 0.8kB | - | X | - | - | X | - | - |
| be / arci / applet / FallbackAudioClip.class | 0.6kB | - | X | - | - | X | - | - |
| be / arci / applet / I18NDelegate.class | 2.0kB | - | - | X | X | X | X | X |
| be / arci / applet / Applicet $ Brethren.class | 0.7kB | - | - | - | X | X | X | X |
| be / arci / applet / Applicet $ Context $ Destroyer.class | 0.4kB | - | - | - | X | X | X | X |
| be / arci / applet / Applicet $ Context $ Disposer.class | 0.4kB | - | - | - | X | X | X | X |
| be / arci / applet / Applicet $ Context.class | 3.1kB | - | - | - | X | X | X | X |
| be / arci / applet / Applicet $ Stub.class | 2.2kB | - | - | - | X | X | X | X |
| be / arci / applet / Browser.class | 0.2kB | - | - | - | X | - | - | - |
| be / arci / applet / DummyBrowser.class | 0.4kB | - | - | - | - | - | X | - |
| be / arci / pub / ExecBrowser.class + be / arci / pub / ExecBrowser.properties |
1.3kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / SwingBrowser.class | 1.5kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / EricAlbertBrowser.class + edu / stanford / ejalbert / BrowserLauncher.class |
3.6kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / ColorParameter.class | 0.7kB | - | - | - | - | - | - | Opt. |
| be / arci / pub / ParameterParser.class | 1.1kB | - | - | - | - | - | - | Opt. |
| Files to include in distribution | Approx. jarred size |
JApplicet applet | JApplicet application | Both | ||||
|---|---|---|---|---|---|---|---|---|
| Basic (incl. sound by URL) | Sound by name | I18N | Basic (incl. I18N) | Sound by URL or name | show HTML | Parameter conveniences | ||
| be / arci / applet / Framework.class | 0.3kB | X | X | X | X | X | X | X |
| be / arci / applet / JApplicet.class | 3.5kB | X | X | X | X | X | X | X |
| be / arci / applet / HFile.class (some environments do not require this file) |
0.1kB | X | X | X | X | X | X | X |
| be / arci / applet / Applicet_xx.properties | n.a. | - | - | - | X | X | X | X |
| be / arci / applet / AudioClipFactory.class | 0.8kB | - | X | - | - | X | - | - |
| be / arci / applet / FallbackAudioClip.class | 0.6kB | - | X | - | - | X | - | - |
| be / arci / applet / I18NDelegate.class | 2.0kB | - | - | X | X | X | X | X |
| be / arci / applet / JApplicet $ Brethren.class | 0.6kB | - | - | - | X | X | X | X |
| be / arci / applet / JApplicet $ Context $ Destroyer.class | 0.3kB | - | - | - | X | X | X | X |
| be / arci / applet / JApplicet $ Context $ Disposer.class | 0.3kB | - | - | - | X | X | X | X |
| be / arci / applet / JApplicet $ Context.class | 3.3kB | - | - | - | X | X | X | X |
| be / arci / applet / JApplicet $ Stub.class | 2.2kB | - | - | - | X | X | X | X |
| be / arci / applet / Browser.class | 0.2kB | - | - | - | X | - | - | - |
| be / arci / applet / DummyBrowser.class | 0.4kB | - | - | - | - | - | X | - |
| be / arci / pub / ExecBrowser.class + be / arci / pub / ExecBrowser.properties |
1.3kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / SwingBrowser.class | 1.5kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / EricAlbertBrowser.class + edu / stanford / ejalbert / BrowserLauncher.class |
3.6kB | - | - | - | - | - | Opt. | - |
| be / arci / pub / ColorParameter.class | 0.7kB | - | - | - | - | - | - | Opt. |
| be / arci / pub / ParameterParser.class | 1.1kB | - | - | - | - | - | - | Opt. |
Applicet supports easy internationalization with the get/setI18Nxxx class of methods. All you have to do now to make international multi-lingual applets and applications is the following:
The execution environment itself will determine the language your user works in, enabling Applicet to display the appropriate set of messages. If a language is not found, or a single message is not translated, Applicet will use the original language message as a fallback.
Popular browsers (at the time of writing) still use a crippled implementation of java.util.ResourceBundle, that stumbles over its own feet when trying to retrieve a .properties files with the same basename as a .class file. Therefor Applicet resorts to direct support of I18N sets of .properties files, at the same time taking out some of the stingy parts of ResourceBundles. Applicet uses the default locale, and as basename the Applicet subclass name, for retrieving the default I18N set of .properties files used by getI18NString(String) etc. The default locale can be changed with setLocale(Locale), and retrieved by getLocale() (see java.awt.Component.setLocale() and java.applet.Applet.getLocale()). If this is not of your liking, you can retrieve a specific I18N set with the getI18NSet() methods and use setI18NDefault() to install it as default for getI18NString() etc.
The process for getting from a basename and a Locale to an I18N set is largely the same as with ResourceBundle. If the environment's default locale is l1_C1_v1 (language, country and variant), and l2_C2_v2 the locale to use for the I18N set, that I18N set is built as follows. :
with lower levels supplying the defaults for messages/properties that do not occur at higher levels. (Note that in earlier JDK's the javadoc for java.util.Resourcebundle is wrong on this hierarchy; we implemented it as it is programmed).
With getI18NDefault() you can retrieve the resulting Properties instance for direct manipulation. With getI18NSet(String,Locale) you can also directly retrieve a differently named I18N set of .properties files directly, without influencing the default set used by getI18NString(String) etc.
TIP: You can test your Applicet application for different locales by passing language and/or country as parameters to the java program. As an example for french Canadian :
java -Duser.language=fr -Duser.region=CA MyApplicet
You can also do the same for testing it as an applet with the AppletViewer:
appletviewer -J-Duser.language=fr -J-Duser.region=CA MyApplicetDocument.html
Doing the same in a Windows.x webbrowser requires changing the operating system's locale settings and rebooting.
For completeness, we repeat the Java 2 (JDK13) description of .properties file syntax here
As a consequence an applet calling showDocument() may cause it's hosting document to be replaced by another document, implicating that the applet itself is stopped and hidden (and possibly a new instance of it created and started in the new document). That is why applets will often use the target argument in showDocument().
This is not the case for an Applicet application; the most common use of showDocument() in Applicet applications will probably be to display nicely formatted user information, or even application-generated HTML content, without affecting the running Applicet application. Also Applicet applet showDocument() calls will typically be made while connected to the Internet, whereas this may not be so when the Applicet application calls showDocument().
An Applicet application's AppletContext (Applicet.Context) delegates the display of documents (showDocument(URL urlDocument, String sTarget)) to an implementation of the Browser interface, that can be set by a call to (Applicet.Context)getAppletContext())setBrowser(Browser). The default Browser implementation is DummyBrowser, that does nothing at all; a few other implementation examples, with source code, are provided in the package be.arci.pub. A Browser implementation is free to ignore sTarget (just as it is free to ignore the complete showDocument() request).
The difference in execution environment for Applicet applets and applications may leed to the need to display different documents; the method isApplication() may be of use here. Anyway (but depending on the actual Browser implementation you use), if String sDocument represents a path to a document relative to the Applicet's documentbase, both Applicet applet and Applicet application will be able to display the same document with the same method call as such:
//executing somewhere in the Applicet subclass code String sDocument = "mypath/mydocument.html"; URL urlDocument = new URL(getDocumentBase(), sDocument); getAppletContext().showDocument(urlDocument);
public class MyAnimation
|
|
Applicet Framework for Applets and Applications v2.03 | ||||||
| PREV NEXT | FRAMES NO FRAMES | ||||||