Previous Section  < Day Day Up >  Next Section

13.4 Java Applets

A few years ago, it seemed that the whole world was going Java crazy. Created by Sun Microsytems, this powerful programming language seemed to offer an end to crossplatform problems. Programs written in Java can run on any operating system: Mac, Unix, Windows, whatever. Java also offered programmers the opportunity to write sophisticated applications that could run in the form of a compact file, called an applet, within any browser. Java applets can provide sophisticated graphics and user interface elements that go well beyond what HTML can do (Figure 13-8). In fact, Java can be used not only for graphics and multimedia, but to build complete applications like word processors, spreadsheets, or mortgage calculators that can live right in a Web page. For loads of sample applets, visit .

In this example, a Java applet lets you interactively determine whether your body mass is appropriate for your age and height. Through the use of custom interface elements (such as the sliders under the height and weight columns), you control the size of the "man" and receive instant feedback in various form fields. (In this example, only the area between the two horizontal rules is the actual applet. Everything else is HTML.)

In the end, Applets didn't make as big a splash on Web pages as industry forecasters originally thought. One of Java's limitations is that its applets don't work unless a Web page visitor has a special software program called a Java Virtual Machine. This program translates the Java code into instructions appropriate for the visitor's particular operating system. As with plug-ins, virtual machines require lengthy downloads and installations that scare off many potential users. In addition, unlike JavaScript, which is fairly easy to learn, Java is not for the faint of heart. It's a complex language that requires a lot of skill and practice to do well.

But when the time comes that you've been handed a Java applet for insertion onto, say, a client's page, here's how to do it.

To insert a Java applet, choose InsertMediaApplet, or choose Applet from the Media menu on the Common tab of the Insert bar. When the Select File dialog box appears, find and double-click the Java applet file you want to insert. (Java applets have a .class or .jar extension.)

After you insert it, the applet appears on your Web page as a gray box with a coffee cup logo in the middle. Unfortunately, you can't preview it within Dreamweaver; press the F12 key to see it run in your Web browser.

13.4.1 Applet Properties

You set properties for applets using the Property inspector (see Figure 13-9), just as for any HTML object. The name, margins, alignment, and width/height controls work just as they do for Flash movies (see Section 13.1.2). Java applets, however, offer a few specialized controls:

  • Code. The name of the applet file appears in the Code field. If you wish to use a different file, click the folder icon and select another applet.

  • Base. The Base field lists the folder that contains the applet file. When you insert an applet, Dreamweaver automatically fills in this field.

    Java, JavaScript

    Is Java the same as JavaScript?

    No, and don't get the two confused.

    Java is a full-featured programming language that programmers use to create elaborate programs that can run with or without a Web browser. JavaScript, on the other hand, is a much simpler, scripting language that Web designers use to add interactivity to Web pages.

    Why are their names so similar? Years ago, Netscape invented a programming language called LiveScript to enhance Navigator with interactive forms, dialog boxes, and so on. When Java appeared on the scene, Netscape renamed LiveScript to JavaScript to cash in on the excitement. However, the two are distinct languages without any technical relationship.

    Ah, marketing.

  • Alt. For the benefit of visitors whose browsers don't support Java (or who have turned Java off), you can provide an alternative image or text description. Type the text in the Alt field, or click the little folder icon and select a GIF or JPEG file that will appear in place of the Java applet. The image will appear automatically if the Java Virtual Machine isn't installed.

Some applets may have properties in addition to the ones listed in the Property inspector. To add these properties, click the Parameters button. For example, the applet ticker.class shown in Figure 13-9 produces a ticker-tape display on a Web page. In order to let the applet know what message it needs to present, you must add a parameter called message. The value of that parameter would be the message: "Welcome to my home page. This ticker-tape display is truly annoying, isn't it?"

In the Properties inspector for a Java applet, a new Parameters button appears.
    Previous Section  < Day Day Up >  Next Section