JAppletFrame

JappletFrameDemo - a test and demo program using JAppletFrame, running as an applet
> Unfortunately, your browser does not understand the <applet> tag. the following is an image. JAppletFrameDemo image

The JAppletFrame is a class that allows applets to be easily converted so they can be used as both applets and applications by simply replacing JApplet by JAppletFrame and adding a simple main method. It is particularly well suited for development of new programs that run as applications but also allow use as applets because it can distinguish between the different modes of operations. In addition to creating a JFrame and loading the applet into it when the program is run as an application, the class overrides several JApplet methods so they will work in the context of a application. In most cases, methods were overridden in meaningful ways. For example, showStatus displays the message in a text field. The getParameter method is extended in two different ways. Three of the AppletContext methods have been implemented with useful behaviors. In addition, new methods allow determining how the applet is being used and allow customizing its behavior for the particular environment. It requires Java JDK1.5 or above.

The demo is designed to test most of the new methods. The other examples may be more interesting than the demo:
JAppetFrameDemo.HTML - a test and demo program that uses many of JAppletFrame's methods
TumbleItem - a classic Java applet application
Tetris - JApplet version of the classic game
DocumentEventDemo - a Java tutorial example
Graph - full featured graphing program that is useful in its own right
MerryChristmas - an electronic Christmas card using multimedia

To convert a normal JApplet file into a JAppletFrame, the following changes would be needed assuming that the JAppletFrame.jar file exists in the same folder:
1. Inherit JAppletFrame instead of JApplet.
2. Add a main method with the following general format:

    public static void main (String [] args) {
       JAppletFrameDemo applet = new JAppletFrameDemo();
       applet.displayJFrame(applet, "This is the title", 540, 465, args);
    } // end main method
 
3. If needed, modify the existing code. If the applet uses parameters, then an alternative may be needed. For example, the normal 1 getParameter method could be replaced by the new 2 parameter method if the extended 1 parameter method is not appropriate

In step 2, substitute your class name for JAppletFrameDemo. The second parameter for the displayJFrame appears in the title bar. The numbers 540 and 465 specify the desired width and height of the window in the JFrame. The call to applet.displayJFrame could be replaced by

JFrame a = applet.displayJFrame(...);
if desired. That would allow further adjustments in the frame. For example,
a.pack( );

To compile your program use
javac -classpath .;JAppletFrame.jar; JAppletFrameDemo.java
replacing JAppletFrameDemo by the name of your Java file.

Because the applet is loaded into a JFrame when it is run as an application, most applet operations are available and work normally. However some applet operations are not normally available in applications so JAppletFrame overrides some JApplet methods to provide equivalent operation or prevent exceptions. To make the class suitable for new program development, some new methods were added the class to determine how it is being run so the program can customize itself accordingly. This means that a single program can have the advantages of an applet when run as an application without the normal security restrictions of an applet. Moreover the same program can be run as an applet with custom methods that prevent it from causing security exceptions.

You can look at JAppletFrame's documentation for more details.

Disclaimer: Users must determine if the JAppletFrame and its methods meets their needs.

You can download just the JAppletFrame files or those files together with a test/demo program from the down load page. Both versions include JavaDoc documentation.

When the demo is run as an application one can browse to select the files using the "Pick sound file" or "Pick file" buttons. When run as an applet, the user will need to type or paste file names into the file name text box.

The following sound files are in the MultiMedia subfolder folder and can be typed or copied into the sound file name text box:

The some of the text files available to be displayed are: