Creating a Quick, Basic Sample Applet or Application

The New Applet SmartGuide creates an applet or application to your specifications without you having to write any Java code.  You can also have it create some sample code in the applet, which you can run to see quick results.  Except where differences between applets and applications are specified, the term "applet" refers to both applets and applications.

The sample applet displays the words "Welcome to VisualAge" in a plain window.  If the applet is threaded, the words scroll across the window.

To create the sample applet:

  1. Launch the New Applet SmartGuide by clicking the New Applet button newapplUp.gif (1052 bytes).
  2. Enter names for the applet, project, and package.
  3. Ensure both the Browse applet when finished check box and the Compose the class visually check box are cleared.
  4. Click Next.
  5. If you want to run the applet as a stand-alone application, enable the Yes... option so that the SmartGuide will generate the main method.  If you select the other option, you will only be able to run the applet in an applet viewer.
  6. The applet will display text that is either static or scrolling, depending on whether the applet runs on a thread.  If you wish to create the scrolling (threaded) version, enable the Yes... option.
  7. Click Next.  You do not need to set any event listeners, so click Next again.
  8. Enable the Write Example checkbox.

At this point, you can click Finish, and leave the remaining SmartGuide settings as they are.  The SmartGuide creates the applet in the project and package that you specified.  When you browse the package, the applet will have a symbol (jexec.gif (864 bytes)) next to it that shows that it can be run.

To run the applet in the applet viewer, select Run, In applet viewer from the applet's pop-up menu.  If you generated the main method, you can also run it as an application by selecting Run, Run main from the pop-up menu.

Making Changes to the Generated Applet
If you click on the applet program element in the Workbench, the project browser, or the package browser, the Source pane shows the applet declaration and its fields.  You can change the default value of the fields to change the way the applet appears.

For example, change the font from TimesRoman to Helvetica, and the text string from "Welcome to VisualAge" to "This is my applet."  Save the changes by typing Ctrl+S.   Run the applet again to see the changes.

You can also make changes to an applet while it is running.  To make run-time changes to the sample applet:

  1. Start the sample applet by selecting Run, In Applet Viewer from the applet's pop-up menu.
  2. Once the applet is running, select Stop from the Applet menu in the Applet Viewer.
  3. In the applet's Source pane in the IDE, change the applet text to, for example, "This is a run-time change."
  4. Type Ctrl+S to save the change.
  5. In the Applet Viewer, select Reload from the Applet menu.  The applet will start up again, with the new text.

ngrelc.gif (533 bytes)
Creating an Applet or Application
Running an Applet from the IDE
Running an Application from the IDE
Making Run-Time Changes to an Applet