Applets are generally small, specialized programs that are downloaded and run within a Java-enabled web browser. Applets operate within constraints that provide security from remote system intrusion.
You can compose and test an applet in the Visual Composition Editor. To run an applet in a web page, export the applet class and edit the web page source file to include the applet.
VisualAge provides applet beans from the
com.sun.java.swing and
java.applet packages, as well as others.
Bean | Description |
---|---|
JApplet (Swing) or Applet (AWT) | A program that can run in a compatible web browser |
Changing Applet or JApplet properties
Use the bean property sheet to change default property settings. To open the property sheet for a JApplet, select the JApplet bean from the Beans List.
Arranging beans in an applet
Use either of the following methods:
Accessing the applet context
The applet context represents the environment in which an applet is running. It provides methods that perform the following:
To access these applet context methods, tear off the appletContext property of the Applet or JApplet bean.
Accessing the document or applet URL for an Applet or JApplet bean
To get the URL of the HTML file where the applet is running, connect to the documentBase property or the getDocumentBase method. To get the URL of the applet, connect to the codeBase property or the getCodeBase method.
Providing information about the applet for an Applet or JApplet bean
To define information about the applet, from the Methods page, edit the getAppletInfo method. To get the applet information for an About dialog, connect to the appletInfo property or the getAppletInfo method.
Exporting an applet class
Do the following to export the applet:
Adding an applet in an HTML file
Specify the applet in your web page source file at the location where you want the applet to run. If VisualAge generated an HTML file when you exported the applet, you must edit the source to specify attributes for the <applet> tag.
Use the <applet> tag to identify the applet class and to specify the dimensions of the bounding rectangle in which the applet is to run. The following example specifies an applet named MyApplet that runs in a 100 by 80 pixel rectangle.
<applet code="MyApplet.class" width=100 height=80></applet>
Bean--specific tasks
For attributes that you can specify in the Applet tag, refer to books that document HTML.
For examples, see the BookmarkList class in the com.ibm.ivj.examples.vc.swing.bookmarklist and com.ibm.ivj.examples.vc.bookmarklist packages. These examples are shipped in the IBM Java Examples project.
Visual bean basics
Using VisualAge beans in visual composition
Creating an applet
Creating a class
Exporting a class
Adding the IBM Java Examples project
Applet beans
BookmarkList sample
Accessing a JApplet bean in the Visual Composition Editor
JApplet beans contain a default content pane that completely covers the base bean. With the exception of a JMenuBar, you add visual beans to the content pane. You can access the covered JApplet bean in the Beans List.
Resizing or moving a JApplet bean in the Visual Composition Editor
JApplet beans (like Swing window beans) contain a default content pane that completely covers the base bean. With the exception of a JMenuBar, you add visual beans to the content pane. To select the JApplet bean and not the content pane, which is necessary for moving or resizing, select the JApplet bean in the Beans List.
Replacing the content pane for a JApplet bean
To replace the default content pane, delete it and add another container component. When you delete the content pane, a warning appears indicating that the content pane is missing. If you save the bean without specifying a new content pane, the Visual Composition Editor adds a JPanel bean.