Java Reference
In-Depth Information
Note that Java is case sensitive. You can't enter public with a capital P - if you do the program won't
compile. This applet will just display a message when you run it. The mechanics of how the message
gets displayed are irrelevant here - the example is just to illustrate how an applet goes into an HTML
page. If you compile this code and save the previous HTML page specification in the file
MyFirstApplet.html in the same directory as the Java applet code, you can run the applet using
appletviewer from the JDK with the command:
appletviewer MyFirstApplet.html
This will display a window something like that shown below:
In this particular case, the window is produced under Windows 95/98/NT/2000. Under other operating
systems it is likely to look a little different since Java 'takes on' the style of the platform on which it is
running. Since the height and width of the window for the applet is specified in pixels, the physical
dimensions of the window will depend on the resolution and size of your monitor.
This example won't work with Internet Explorer or Netscape Navigator as neither of these supports Java
2 directly. Let's see what can be done about that.
Making Applets Run in Any Browser
The key to making all your Java applets work with any browser is to make sure the Java 2 Plug-in is
installed for each browser that views any of your web pages that contain applets. Making sure that each
browser that runs your applet has a Java 2 Plug-in installed is not as hard as you might imagine because
you can arrange for it to be automatically downloaded when required - assuming that the computer is
online to the Web at the time of course.
The Java Plug-in is a module that can be integrated with Internet Explorer (version 4.0 or later) or Netscape
Navigator (version 6.0 or later) to provide full support for Java 2 applets. It supports the use of the <applet>
tag on any version of Windows from Windows 95 to Windows XP, as well as Linux and Unix.
To enable automatic download of the Java 2 Plug-in with your applets, you need to add some HTML to
your web page that invokes a VBScript that handles the download and installation process for the plug-in.
To modify our HTML to do this we just need to add one extra tag:
Search WWH ::




Custom Search