Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Editing the HTML File

Editing the HTML file is an easy way to change the position at which your applet appears. You can center the applet, justify it on the left side of the browser screen, or justify it on the right side of the browser screen. Many of the applets created in this book will have parameters that reside in the HTML file. Changing them will alter the behavior of the applet.

After the three HelloWorld files are on the server in the correct directory, the main HTML file must be edited so that users have the chance to bring up your applet. As mentioned earlier, the main HTML file on your Web server will probably have a special name such as index.html. There’s a difference between writing an applet and testing it on a local machine, and uploading to a Web server and testing on the server. Details such as what the name of the default (main) HTML page is are important.

For now, you’ll have the main HTML file bring up HelloWorld.html. Open your main HTML file in a text editor. Add the following line:

<h3><p>Run <a href=HelloWorld.html> <i>HelloWorld</a></h3><p>

A new line will appear when your browser opens the HTML at your site, as shown in Figure 3.6.


Figure 3.6  The line that was added to the HTML file causes Run HelloWorld to show in the browser.

When you click on the HTML line, you’ll see the HelloWorld applet run in your browser. The source code is available for viewing with a line at the bottom labeled “The source,” as shown in Figure 3.7. All HTML files created by J++ make the source code available.

Offering Your Source Code for Download

Most people who want to take a look at your source code don’t want to look at it from within a browser. They usually want to download it and look at it on their computers. For this reason, it’s a good idea to include an archived version of the source code. The best way to do this is to zip the source code into a separate file. You can then add another line that offers zipped source code for downloading.

Zip the source code to a file named HelloWorld.zip. You’ll need the latest version of WinZip that supports long filenames. It can be found at http://www.winzip.com.

By the way, WinZip can be downloaded and used free of charge for a limited time. If you use it after 30 days, you need to register it.

Add the following line to your HelloWorld.html file, and the archived source code will be available for downloading:

          <a href=HelloWorld.zip>The source zipped.</a>

Now that you know how to make the changes in the HTML file for the HelloWorld applet, it’s time to take a look at the complete file. Listing 3.1 has the HTML source code for the HelloWorld applet.

Listing 3.1 The Complete HelloWorld.html File

1   <HTML>
2   <HEAD>
3   <TITLE>HelloWorld Test HTML Page</TITLE>
4   </HEAD>
5   <BODY>
6       <applet
7           code=HelloWorld.class
8           name=HelloWorld
9           width=320
10          height=200 >
11          <param name=label value="Hello Visual J++ World.">
12          <param name=background value="008080">
13          <param name=foreground value="FFFFFF">
14      </applet>
15
16  <hr>
17  <a href="HelloWorld.java">The source.</a>
18  <a href="HelloWorld.zip">The source zipped.</a>
19
20  </BODY>
21  </HTML>


Figure 3.7  Your applet runs from inside of your browser, and the source code is available for viewing.

Summary of Steps to Make Applets Live

1.  Connect to your server with an FTP program, such as WS_FTP32.
2.  Upload HTML, Java, and Class files.
3.  Edit the main HTML file by adding this:
<h3><p>Run <a href=HelloWorld.html>
    <i>HelloWorld</a></h3><p>
4.  Test the file with your browser.

Summary

Uploading your applets to a Web server is an important part of the development process. It’s one you need to be familiar with so that you can do it without a lot of aggravation.

Editing your HTML files is important too. The appearance of your Java program relies on your ability to edit the HTML file and correctly set the applet parameters.

A good tool to use for uploading files is WS_FTP. A trial version can be downloaded and used free of charge for a limited time.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.