Creating a Java Applet with the Applet on HTML Template

Thanks for using this pre-release version of Visual J++.

To create a Java applet using the Applet on HTML template

Use this procedure to create a basic JavaÖ applet. This applet can be run from the development environment or it can be called from a Web page. This procedure will run the applet from the development environment. See Running an Applet from an HTML Page for the procedure for running your applet within a browser.

Tip Before beginning the following procedure, close all open projects by clicking Close Project on the File menu for each open project.

To create a basic Java applet

  1. On the File menu, click New Project.

    The New Project dialog box appears.

  2. On the New tab, click the ô+ö sign to the left of the Visual J++ Projects folder to display additional folders for specific types of Visual J++ projects.

    Folders for Web Pages, Applications, and Components appear.

  3. Open the Web Pages folder.

    Applet on HTML, Code-Behind HTML, and COM Control on HTML icons appear in the rightmost pane of the New Project dialog.

  4. Click the Applet on HTML icon.

  5. Enter a name for your applet project into the Name text box.

  6. Click Open.

    A collapsed view of your applet project appears in the Project Explorer.

  7. Expand the project icon by clicking the ô+ö sign to the left of your projectÆs name in the Project Explorer.

  8. To view your appletÆs code, highlight the appletÆs .java file, and click View Code on the shortcut menu.

    The appletÆs code appears in an interactive Code Editor where you can make modifications to the code.

  9. Add the following code for a paint() method to your applet class after the init() method:
    public void paint( Graphics g )
    {
    g.drawString( "Hello, World!", 50, 25 );
    }
    

To see the results of the code youÆve added to the template, you will need to compile and run the applet. See Building and Running an Applet with an Applet Viewer for the procedures to walk you through this process.