Chapter 11

Building a Simple Java Applet with Visual J++

by Hiro Ruo


CONTENTS

This chapter demonstrates the use of the Applet Wizard to create a simple Java applet. This will give you an introduction to the Visual J++ compiler.

Wizards

When writing a program, you should focus on the requirements of the functionality of the program. The inputs and outputs of the program and the actual processing of information are what differentiate one program from another. In today's programming environment, there is much more to consider when writing code: the correct structuring of the interface to the operating environment; the support of basic operating system features such as mouse control, windowing, and multitasking; and so on. The complexity of the current computing environments has made programming a challenge.

In addition to the capability to build and compile a piece of source code, many modern compilers also provide a more language-independent interface for developers to create programs, called a wizard. Wizards will take some of the most common structuring requirements of a typical program and an automated, friendly interface to incorporate these features and requirements into a starting template. After running a wizard, the basic infrastructure of a program is in place, and the developer needs to implement only the differentiating functionality of the planned program. Using wizards greatly reduces time to completion by providing a fairly complete starting point.

Visual J++ Applet Wizard Overview

The Visual J++ development environment's wizard, Applet Wizard, provides a clear, intuitive interface that allows you to select from several key feature supports of the Visual J++ targeted environment:

Using the Applet Wizard provides the basis for an applet or application and eliminates the need to manually incorporate lines of code for these functions into the software.

This chapter investigates the use of the Applet Wizard and the features supported in more detail. Let's create a simple Java program to demonstrate the Applet Wizard.

Running the Applet Wizard

Let's start by creating a new program, a template source code. To run the Applet Wizard, you must first create a new project workspace. Under the File menu of the Microsoft Developer StudioÐVisual J++ window, select New to create a new project. The dialog box shown in Figure 11.1 appears. Select Project Workspace and proceed. Another dialog box will appear (see Figure 11.2), asking for the type of project workspace and a name of the project.

Figure 11.1 : The New Project dialog box.

Figure 11.2 : The Project Workspace dialog box.

Note that this is the point at which you can elect to use the Java Applet Wizard for Visual J++. Select the Applet Wizard to create the new program workspace with the name JAW1 (Java Applet Wizard 1-not an indication of the type of program you'll be creating). Notice also the Platform option of this dialog box; to create a Java applet, the Java Virtual Machine should be selected. Any additional packages that work with Microsoft Developer Studio may appear here as valid selection options.

Selecting Create after completely filling out the dialog box will take you to the first step of the Applet Wizard.

In step 1 of the Applet Wizard, you will be allowed to select how you want your program to be run: as an applet, a standalone application, or both. (See Figure 11.3.) You will be creating a program to be run as both an applet and application in this example. The lines in Listing 11.1 are what the wizard creates. Note the additional support for parameter definitions needed to run the program as both a standalone application and an applet.

Figure 11.3 : Java Applet Wizard, step 1.


Listing 11.1. An applet and an application.

//******************************************************************************

// JAW1.java:    Applet

//

//******************************************************************************

import java.applet.*;

import java.awt.*;

import JAW1Frame;  //This is added as support for application



//==============================================================================

// Main Class for applet JAW1

//

//==============================================================================

public class JAW1 extends Applet implements Runnable

{

.

.

.

    // STANDALONE APPLICATION SUPPORT:

    //        m_fStandAlone will be set to true if applet is run standalone

    //--------------------------------------------------------------------------

    boolean m_fStandAlone = false;

.

.

.

    // STANDALONE APPLICATION SUPPORT

    //     The GetParameter() method is a replacement for the getParameter() 

    // method defined by Applet. This method returns the value of the 

    // specified parameter; unlike the original getParameter() method, this

    // method works when the applet is run as a standalone application, as 

    // well as when run within an HTML page.

    // This method is called by GetParameters().

    //--------------------------------------------------------------------------

    String GetParameter(String strName, String args[])

    {

        if (args == null)

        {

            // Running within an HTML page, so call original getParameter().

            //------------------------------------------------------------------

            return getParameter(strName);

        }



        // Running as standalone application, so parameter values are 

        // obtained from

        // the command line. The user specifies them as follows:

        //

        //    JView JAW1 param1=<val> param2=<"val with spaces"> ...

        //----------------------------------------------------------------------

        int    i;

        String strArg    = strName + "=";

        String strValue = null;



        for (i = 0; i < args.length; i++)

        {

            if (strArg.equalsIgnoreCase(args[i].substring(0, strArg.length())))

            {

                // Found matching parameter on command line, so extract its value.

                // If in double quotes, remove the quotes.

                //--------------------------------------------------------------

                strValue= args[i].substring(strArg.length());

                if (strValue.startsWith("\""))

                {

                    strValue = strValue.substring(1);

                    if (strValue.endsWith("\""))

                        strValue = strValue.substring(0, strValue.length() - 1);

                }

            }

        }



        return strValue;

    }



    // STANDALONE APPLICATION SUPPORT

    //     The GetParameters() method retrieves the values of each of the applet's

    // parameters and stores them in variables. This method works both when the

    // applet is run as a standalone application and when it's run within an HTML

    // page.  When the applet is run as a standalone application, this method is

    // called by the main() method, which passes it the command-line arguments.

    // When the applet is run within an HTML page, this method is called by the

    // init() method with args == null.

    //--------------------------------------------------------------------------

    void GetParameters(String args[])

    {

        // Query values of all Parameters

        //--------------------------------------------------------------

        String param;



        // Variable1: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable1, args);

        if (param != null)

            m_Variable1 = param;



        // Variable2: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable2, args);

        if (param != null)

            m_Variable2 = Integer.parseInt(param);



        // Variable3: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable3, args);

        if (param != null)

            m_Variable3 = Boolean.valueOf(param).booleanValue();



        // Variable4: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable4, args);

        if (param != null)

            m_Variable4 = Double.valueOf(param).doubleValue();



        // Variable5: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable5, args);

        if (param != null)

            m_Variable5 = Float.valueOf(param).floatValue();



        // Variable6: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable6, args);

        if (param != null)

            m_Variable6 = Long.parseLong(param);



        // Variable7: Parameter description

        //--------------------------------------------------------------

        param = GetParameter(PARAM_Variable7, args);

        if (param != null)

            m_Variable7 = param;



    }



    // STANDALONE APPLICATION SUPPORT

    //     The main() method acts as the applet's entry point when it is run

    // as a standalone application. It is ignored if the applet is run from

    // within an HTML page.

    //--------------------------------------------------------------------------

    public static void main(String args[])

    {

        // Create Toplevel Window to contain applet JAW1

        //----------------------------------------------------------------------

        JAW1Frame frame = new JAW1Frame("JAW1");



        // Must show Frame before we size it so insets() will return valid values

        //----------------------------------------------------------------------

        frame.show();

               frame.hide();

        frame.resize(frame.insets().left + frame.insets().right  + 320,

                     frame.insets().top  + frame.insets().bottom + 240);



        // The following code starts the applet running within the frame window.

        // It also calls GetParameters() to retrieve parameter values from the

        // command line, and sets m_fStandAlone to true to prevent init() from

        // trying to get them from the HTML page.

        //----------------------------------------------------------------------

        JAW1 applet_JAW1 = new JAW1();



        frame.add("Center", applet_JAW1);

        applet_JAW1.m_fStandAlone = true;

        applet_JAW1.GetParameters(args);

        applet_JAW1.init();

        applet_JAW1.start();

               frame.show();

    }



    // JAW1 Class Constructor

    //--------------------------------------------------------------------------

    public JAW1()

    {

        // TODO: Add constructor code here

    }

.

.

.

    // The init() method is called by the AWT when an applet is first loaded or

    // reloaded.  Override this method to perform whatever initialization your

    // applet needs, such as initializing data structures, loading images or

    // fonts, creating frame windows, setting the layout manager, or adding UI

    // components.

        //--------------------------------------------------------------------------

    public void init()

    {

        if (!m_fStandAlone)

            GetParameters(null);

.

.

.

        // TODO: Place additional initialization code here

    }



    // Place additional applet clean up code here.  destroy() is called when

    // when you applet is terminating and being unloaded.

    //------------------------------------------------------------------------

    public void destroy()

    {

        // TODO: Place applet cleanup code here

    }

.

.

.

    // TODO: Place additional applet code here



}


The wizard creates the lines of code in Listing 11.2 to support event handling and frame configuration for running the program as a standalone application.


Listing 11.2. A standalone application frame and event handler.

//******************************************************************************

// JAW1Frame.java:

//

//******************************************************************************

import java.awt.*;



//==============================================================================

// STANDALONE APPLICATION SUPPORT

//     This frame class acts as a top-level window in which the applet appears

// when it's run as a standalone application.

//==============================================================================

class JAW1Frame extends Frame

{

    // JAW1Frame constructor

    //--------------------------------------------------------------------------

    public JAW1Frame(String str)

    {

        // TODO: Add additional construction code here

        super (str);

    }



    // The handleEvent() method receives all events generated within the frame

    // window. You can use this method to respond to window events. To respond

    // to events generated by menus, buttons, etc. or other controls in the

    // frame window but not managed by the applet, override the window's

    // action() method.

    //--------------------------------------------------------------------------

    public boolean handleEvent(Event evt)

    {

        switch (evt.id)

        {

            // Application shutdown (e.g. user chooses Close from the 

            // system menu).

            //------------------------------------------------------------------

            case Event.WINDOW_DESTROY:

                // TODO: Place additional clean up code here

                dispose();

                System.exit(0);

                return true;



            default:

                return super.handleEvent(evt);

        }

    }

}


In addition, you can select the commenting options provided by the Applet Wizard. Selecting Yes and individually selecting the Explanatory Comments and TODO Comments check boxes creates an initial piece of code with comments on what the Applet WizardÐcreated lines do and any space allocated for items to be added to the starting template. Throughout the example, comments are placed to explain the following lines of code and in sections where additional lines of code (TODO) can be added.

At this point as at any throughout the use of the Applet Wizard, if these are all the options you want to have implemented, select Finish to create the starting template. Proceed with Next to investigate the other features of the Applet Wizard.

Selecting Next takes you to step 2 of the Applet Wizard (see Figure 11.4). In step 2, the Applet Wizard provides a selection option to create a sample HTML file for the program being written. Enabling this option provides an HTML file with the applet embedded. This allows you to use HTML to view your program and see how it can be in built into a Web page.

Figure 11.4 : The Java Applet Wizard, step 2.

In this step, you can also select the working window size of your program. The default value is 320´240, or one-fourth of the screen in VGA-standard 640´480 mode. Enter the pixel values of the desired applet size in these boxes. In this case, use the default values. The lines of code in Listing 11.3 are added to format the applet size.


Listing 11.3. Applet sizing.

// If you use a ResourceWizard-generated "control creator" class to

// arrange controls in your applet, you may want to call its

// CreateControls() method from within this method. Remove the following

// call to resize() before adding the call to CreateControls();

// CreateControls() does its own resizing.

//----------------------------------------------------------------------

        resize(320, 240);


Selecting Next takes you to step 3 of the Applet Wizard (see Figure 11.5). Option 1 in step 3 of the Applet Wizard enables multithreading support in your program. Because this program will be run on multiple platforms, some of which may provide multithreading functionality, you should enable this option. (It also demonstrates the full capabilities of the Applet Wizard.) The code in Listing 11.4 is added to the source being created. Note the run() function is called when the thread is started. The code listed is for the support of the default multithreading option.

Figure 11.5 : The Java Applet Wizard, step 3.


Listing 11.4. Multithreading.

// THREAD SUPPORT:

    //        m_JAW1    is the Thread object for the applet

    //--------------------------------------------------------------------------

    Thread     m_JAW1 = null;

.

.

.

  //        The start() method is called when the page containing the applet

    // first appears on the screen. The AppletWizard's initial implementation

    // of this method starts execution of the applet's thread.

    //--------------------------------------------------------------------------

    public void start()

    {

        if (m_JAW1 == null)

        {

            m_JAW1 = new Thread(this);

            m_JAW1.start();

        }

        // TODO: Place additional applet start code here

    }



    //        The stop() method is called when the page containing the applet is

    // no longer on the screen. The AppletWizard's initial implementation of

    // this method stops execution of the applet's thread.

    //--------------------------------------------------------------------------

    public void stop()

    {

        if (m_JAW1 != null)

        {

            m_JAW1.stop();

            m_JAW1 = null;

        }



        // TODO: Place additional applet stop code here

    }



// THREAD SUPPORT

//  The run() method is called when the applet's thread is started. If

// your applet performs any ongoing activities without waiting for user

// input, the code for implementing that behavior typically goes here. For

// example, for an applet that performs animation, the run() method controls

// the display of images.

//--------------------------------------------------------------------------

public void run()

{

    m_nCurrImage = 0;



// If re-entering the page, then the images have already been loaded.

// m_fAllLoaded == TRUE.

//----------------------------------------------------------------------

      if (!m_fAllLoaded)

      {

            repaint();

            m_Graphics = getGraphics();

            m_Images   = new Image[NUM_IMAGES];



        // Load in all the images

        //------------------------------------------------------------------

        MediaTracker tracker = new MediaTracker(this);

        String strImage;



        // For each image in the animation, this method first constructs a

        // string containing the path to the image file; then it begins

        // loading the image into the m_Images array.  Note that the call to

        // getImage will return before the image is completely loaded.

        //------------------------------------------------------------------

        for (int i = 1; i <= NUM_IMAGES; i++)

        {

            // Build path to next image

            //--------------------------------------------------------------

            strImage = "images/img00" + ((i < 10) ? "0" : "") + i + ".gif";

            if (m_fStandAlone)

                    m_Images[i-1] = Toolkit.getDefaultToolkit()

                                    .getImage(strImage);

            else

                    m_Images[i-1] = getImage(getDocumentBase(), strImage);



                tracker.addImage(m_Images[i-1], 0);

        }



        // Wait until all images are fully loaded

        //------------------------------------------------------------------

        try

        {

             tracker.waitForAll();

             m_fAllLoaded = !tracker.isErrorAny();

        }

        catch (InterruptedException e)

        {

              // TODO: Place exception-handling code here in case an

              //       InterruptedException is thrown by Thread.sleep(),

              //       meaning that another thread has interrupted this one

        }



        if (!m_fAllLoaded)

        {

            stop();

            m_Graphics.drawString("Error loading images!", 10, 40);

            return;

        }



        // Assuming all images are same width and height.

        //--------------------------------------------------------------

        m_nImgWidth  = m_Images[0].getWidth(this);

        m_nImgHeight = m_Images[0].getHeight(this);

    }

    repaint();

    while (true)

    {

        try

        {

            // Draw next image in animation

            //--------------------------------------------------------------

            displayImage(m_Graphics);

            m_nCurrImage++;

            if (m_nCurrImage == NUM_IMAGES)

                   m_nCurrImage = 0;



            // TODO:  Add additional thread-specific code here

            Thread.sleep(50);

        }

        catch (InterruptedException e)

        {

            // TODO: Place exception-handling code here in case an

            //       InterruptedException is thrown by Thread.sleep(),

            //       meaning that another thread has interrupted this one

            stop();

        }

}

}


Option 2 in step 3 of the wizard enables support for animation in the program. You should select the option for support of animation. In the lines of added code in Listing 11.5, support for animation, including the default animation of a spinning globe, is implemented in the source code being generated.


Listing 11.5. Animation support.

    // ANIMATION SUPPORT:

    //        m_Graphics        used for storing the applet's Graphics context

    //        m_Images[]        the array of Image objects for the animation

    //        m_nCurrImage    the index of the next image to be displayed

    //        m_ImgWidth        width of each image

    //        m_ImgHeight        height of each image

    //        m_fAllLoaded    indicates whether all images have been loaded

    //        NUM_IMAGES         number of images used in the animation

    //--------------------------------------------------------------------------

    private Graphics m_Graphics;

    private Image     m_Images[];

    private int      m_nCurrImage;

    private int      m_nImgWidth  = 0;

    private int      m_nImgHeight = 0;

    private boolean  m_fAllLoaded = false;

    private final int NUM_IMAGES = 18;

.

.

.



    // ANIMATION SUPPORT:

    //        Draws the next image, if all images are currently loaded

    //--------------------------------------------------------------------------

    private void displayImage(Graphics g)

    {

        if (!m_fAllLoaded)

            return;



        // Draw Image in center of applet

        //----------------------------------------------------------------------

        g.drawImage(m_Images[m_nCurrImage],

                   (size().width - m_nImgWidth)   / 2,

                   (size().height - m_nImgHeight) / 2, null);

    }



    // JAW1 Paint Handler

    //--------------------------------------------------------------------------

    public void paint(Graphics g)

    {

        // ANIMATION SUPPORT:

        //        The following code displays a status message until all the

        // images are loaded. Then it calls displayImage to display the current

        // image.

        //----------------------------------------------------------------------

        if (m_fAllLoaded)

        {

            Rectangle r = g.getClipRect();



            g.clearRect(r.x, r.y, r.width, r.height);

            displayImage(g);

        }

        else

            g.drawString("Loading images...", 10, 20);



        // TODO: Place additional applet Paint code here

    }


Option 3 in this step allows you to enable the support of mouse functions. For this example, you should check all three boxes for mouse support. Doing so will allow the wizard to create the functional infrastructure for support of mouse events in the applet or application. The code in Listing 11.6 is created by the wizard to support mouse events.


Listing 11.6. Mouse functions.

    // MOUSE SUPPORT:

    //        The mouseDown() method is called if the mouse button is pressed

    // while the mouse cursor is over the applet's portion of the screen.

    //--------------------------------------------------------------------------

    public boolean mouseDown(Event evt, int x, int y)

    {

        // TODO: Place applet mouseDown code here

        return true;

    }



    // MOUSE SUPPORT:

    //        The mouseUp() method is called if the mouse button is released

    // while the mouse cursor is over the applet's portion of the screen.

    //--------------------------------------------------------------------------

    public boolean mouseUp(Event evt, int x, int y)

    {

        // TODO: Place applet mouseUp code here

        return true;

    }



    // MOUSE SUPPORT:

    //        The mouseDrag() method is called if the mouse cursor moves over the

    // applet's portion of the screen while the mouse button is being held down.

    //--------------------------------------------------------------------------

    public boolean mouseDrag(Event evt, int x, int y)

    {

        // TODO: Place applet mouseDrag code here

        return true;

    }



    // MOUSE SUPPORT:

    //        The mouseMove() method is called if the mouse cursor moves over the

    // applet's portion of the screen and the mouse button isn't being held down.

    //--------------------------------------------------------------------------

    public boolean mouseMove(Event evt, int x, int y)

    {

        // TODO: Place applet mouseMove code here

        return true;

    }



    // MOUSE SUPPORT:

    //        The mouseEnter() method is called if the mouse cursor enters the

    // applet's portion of the screen.

    //--------------------------------------------------------------------------

    public boolean mouseEnter(Event evt, int x, int y)

    {

        // TODO: Place applet mouseEnter code here

        return true;

    }



    // MOUSE SUPPORT:

    //        The mouseExit() method is called if the mouse cursor leaves the

    // applet's portion of the screen.

     //--------------------------------------------------------------------------

    public boolean mouseExit(Event evt, int x, int y)

    {

        // TODO: Place applet mouseExit code here

        return true;

    }


Selecting Next takes you to step 4 (see Figure 11.6). In this step, you can define the parameters to be passed to your applet or application. The name, member, variable type, and default values of each parameter are defined. At this point, you may not know the complete set of parameters required. These can be added later; however, it is recommended that when determining the scope of the project, you define as many parameters as possible prior to running the Applet Wizard. It is easier to remove extra parameters that are not needed.

Figure 11.6 : The Java Applet Wizard, step 4.

Listing 11.7 shows the lines added to the program by the wizard. Note the additional parameter support provided in the previous code entry implemented to support running this program as a standalone application.


Listing 11.7. Parameter definitions.

    // PARAMETER SUPPORT:

    //        Parameters allow an HTML author to pass information to the applet;

    // the HTML author specifies them using the <PARAM> tag within the <APPLET>

    // tag.  The following variables are used to store the values of the

    // parameters.

    //--------------------------------------------------------------------------



    // Members for applet parameters

    // <type>       <MemberVar>    = <Default Value>

    //--------------------------------------------------------------------------

    private String m_Variable1 = "";

    private int m_Variable2 = 0;

    private boolean m_Variable3 = false;

    private double m_Variable4 = 0.0;

    private float m_Variable5 = 0.0f;

    private long m_Variable6 = 0;

    private String m_Variable7 = "";



    // Parameter names.  To change a name of a parameter, you need only make

    // a single change.  Simply modify the value of the parameter string below.

    //--------------------------------------------------------------------------

    private final String PARAM_Variable1 = "Variable1";

    private final String PARAM_Variable2 = "Variable2";

    private final String PARAM_Variable3 = "Variable3";

    private final String PARAM_Variable4 = "Variable4";

    private final String PARAM_Variable5 = "Variable5";

    private final String PARAM_Variable6 = "Variable6";

    private final String PARAM_Variable7 = "Variable7";

.

.

.

    // PARAMETER SUPPORT

    //        The getParameterInfo() method returns an array of strings describing

    // the parameters understood by this applet.

    //

    // JAW1 Parameter Information:

    //  { "Name", "Type", "Description" },

    //--------------------------------------------------------------------------

    public String[][] getParameterInfo()

    {

        String[][] info =

        {

            { PARAM_Variable1, "String", "Parameter description" },

            { PARAM_Variable2, "int", "Parameter description" },

            { PARAM_Variable3, "boolean", "Parameter description" },

            { PARAM_Variable4, "double", "Parameter description" },

            { PARAM_Variable5, "float", "Parameter description" },

            { PARAM_Variable6, "long", "Parameter description" },

            { PARAM_Variable7, "String", "Parameter description" },

        };

        return info;

    }


Selecting Next will take you to the final step of the Applet Wizard (see Figure 11.7). A majority of the code is now defined. (Throughout the use of the Applet Wizard, you can select Back to return to a previously decided option to make changes; the current choices will be retained in memory.)

Figure 11.7 : The Java Applet Wizard, step 5.

In the final step, enter any information that will be returned by the getAppInfo() method. This should include any information regarding the source code, including but not limited to the author's name, the copyright date (if one exists), the use of this program, and any other information. Listing 11.8 shows the lines of code added to the program by the wizard.


Listing 11.8. GetAppletInfo() return values.

    // APPLET INFO SUPPORT:

    //        The getAppletInfo() method returns a string describing the applet's

    // author, copyright date, or miscellaneous information.

       //--------------------------------------------------------------------------

    public String getAppletInfo()

    {

        return "Name: JAW1\r\n" +

               "Author: Hiro Yueh-Hung Ruo\r\n" +

               "Created with Microsoft Visual J++ Version 1.0\r\n" +

               "Example for Visual J++ Unleashed, Chapter 11";

    }


The program is now essentially complete. Select Back to make any changes to previous options, or select Finish to complete the code template.

When you select Finish, a summary screen containing some general information regarding the applet/application just created (see Figure 11.8) is displayed. Clicking OK will complete the Applet Wizard and create the program as configured throughout the Applet Wizard.

Figure 11.8 : The Java Applet Wizard summary screen.

The program is now complete (see Figure 11.9). As you can see, a large portion of the planned project is now completed with a few simple choice selections and a few clicks of the mouse. The created source code is listed in the working window. This program, as it stands, can now be compiled and run as an applet or a standalone application.

Figure 11.9 : A Java applet example.

Note that the left window displays a directory-like structure to allow you to select specific sections of the source code created. The program can now be modified to add functionality not created with the Applet Wizard.

The following files are created after you select Rebuild All from the Build menu:

JAW1.class
JAW1.java
JAW1Frame.class
JAW1Frame.java
JAW1.mak
JAW1.ncb
JAW1.html
/IMAGES

The JAW1.class file is created to run the applet as a Java class in a Web page. As part of the default animation support, a set of images is also created in the subdirectory Images.

Note that an executable program has not been created. The code has support for running this program as a standalone application, but you must incorporate and compile this program to create an EXE. However, the applet can now be run with JAW1.html (see Listing 11.9).


Listing 11.9. Sample HTML.

<html>

<head>

<title>JAW1</title>

</head>

<body>

<hr>

<applet

    code=JAW1.class

    id=JAW1

    width=320

    height=240 >

    <param name=Variable1 value="">

    <param name=Variable2 value=0>

    <param name=Variable3 value=false>

    <param name=Variable4 value=0.0>

    <param name=Variable5 value=0.0f>

    <param name=Variable6 value=0>

    <param name=Variable7 value="">

</applet>

<hr>

<a href="JAW1.java">The source.</a>

</body>

</html>


The spinning globe (see Figure 11.10), which otherwise would have taken substantially more time and debugging, is now available for implementation into a Web page.

Figure 11.10 : A Java applet example.

Summary

This chapter demonstrates the power and flexibility of the Visual J++ Applet Wizard. Novice programmers can use this as a method of learning the correct structuring of a fully operational Java applet or simply to create a seemingly complex program to incorporate into a Web page. Advanced developers can use the support provided by the Applet Wizard to get to a better starting point. It's easy to create complex applets by modifying the source code provided. The Applet Wizard is a helpful tool that anyone who wants to write Java using Visual J++ can exploit.