[ Go to October 1997 Table of Contents ]|
If you haven't kept up with the current computing craze, it's time to wake up and smell the coffee. I'm talking about Java of course, just in case you haven't noticed all those coffee-related puns in the headlines recently.
Java is a fairly new programming language, originally developed by Sun Microsystems. Java programs can run under Windows, OS/2, UNIX and the Mac, and special CPU chips will allow future platforms to run programs written in a dialect of Java. No one knows for certain what the future holds, but several companies and individuals are betting heavily that Java will someday replace C and C++ as the application development language of choice.
Scripting languages allow ordinary folks to automate routine tasks and add features to their applications. They're usually slimmed-down versions of professional programming languages, tailored for mortals like you and me.
Despite its glamorous appearance, a Web page is actually a text file. The file's name usually ends with the special extension .htm or .html, indicating it contains HyperText Markup Language (HTML) statements. These statements tell a browser what text and images to display, where and how to display them, and what to do if a user clicks on a portion of the page.
To create your Web page, start by creating a text file like the one shown in the sidebar, "Start with a Skeleton ... ." I've named it PWJava.htm, but you can name it anything you like. Just be sure to add either the .htm or .html extension to the file's name.
This skeleton, or template, HTML file doesn't contain any text or images. If you ask your Web browser to display it (by selecting Open from the browser's File menu), you'll just see a blank page. You'll add to the file later, making it a bit more interesting. But even now this page tells us something. It reveals the basic structure of all HTML files.
As you can see, the template contains just six lines. Each line contains a tag, a small bit of text between acute brackets (< and > signifiying "less than" and "greater than"). The text inside a tag can be upper or lower-case, whichever you prefer.
Two of your template's tags, <HTML> and </HTML>, mark the beginning and ending of the file itself. The browser will process everything between these two tags. It ignores text and tags before the <HTML> tag or after the </HTML> tag.
Your template also contains two other pairs of tags. The first, <HEAD> and </HEAD>, mark the beginning and end of the file's header. Later you'll add a tag in this section that specifies the page's title (what the browser displays in its title bar while you're viewing the page). Other optional tags in this section reveal the file's author, the type of software used to create the file, and even keywords used by Web-search programs to index the page's data.
Inside the body
The browser's title bar now looks nice, but your page remains blank. To fix that, you need to add something to the body section of the file. Let's start with a bit of text. Immediately after the line containing the <BODY> tag, add a line that reads "Click this button and see what happens!" This text will be displayed at the top of your page.
Now you need a button. Start by creating a form, a place on the Web page where user input controls (such as pushbuttons) are displayed. That involves two tags, <FORM> to mark the beginning of the form, and </FORM> to mark its end. The sidebar "Add Some Flesh ...," shows how it's done.
Now you're ready to create a button. To do that, place an <INPUT> tag between the <FORM>and </FORM> tags you added a moment ago. As its name implies, the <INPUT> tag is a general-purpose tag that creates user-input controls. For this project, the tag should read <INPUT type="button" name="btnDemo" value="Click Me" onClick="Clicked()">.
Be a scriptwriter
You may not have realized it, but you've already named your program. Take a look at the <INPUT> tag you used to create your button. Notice the last parameter, onClick? The value of this parameter, Clicked(), is the name of the event handler that will be called whenever your button is clicked.
Now that you know its name, take a look at the full program. You'll find it in "Add Some Flesh ...," near the bottom immediately after the </BODY> tag. As you may have guessed, the program begins with one tag, <SCRIPT>, and ends with another, </SCRIPT>. The <SCRIPT> tag has only one parameter, language, which specifies the scripting language used.
Whew! You're finally ready to write the program itself. Its complete text is shown in "Add Some Flesh ... ." Run it and you'll see that it displays the text "You clicked me!" in the browser's status bar and in a popup alert message box. Once you've clicked the alert box's OK button, the program navigates your browser to the WINDOWS Magazine home page, http://www.winmag.com.
Contributing editor Karen Kenworthy is the author of Visual Basic for Applications, Revealed! (Prima Publishing), a nonprogrammer's introduction to VBA. Contact care of the editor or the addresses on page 20.