Java 1.1 Unleashed
- 56 -
|
Classes | Interfaces | Exception |
AWTCompatibility | ApplicationObserver | HTMLParsingException |
AWTComponentView | DragDestination | |
Alert | DragSource | |
Application | DrawingSequenceOwner | |
BezelBorder | EventFilter | |
Bitmap | EventProcessor | |
Border | ExtendedTarget | |
Button | LayoutManager | |
Color | ScrollBarOwner | |
ColorChooser | Scrollable | |
ColorWell | Target | |
CommandEvent | TextFieldOwner | |
ContainerView | TextFilter | |
DebugGraphics | TextViewOwner | |
DragSession | Window | |
DragWell | WindowOwner | |
DrawingSequence | ||
EmptyBorder | ||
Event | ||
EventLoop | ||
ExternalWindow | ||
FileChooser | ||
Font | ||
FontChooser | ||
FontMetrics | ||
FoundationApplet | ||
FoundationPanel | ||
Graphics | ||
GridLayout | ||
Image | ||
ImageAttachment | ||
ImageSequence | ||
InternalWindow | ||
InternalWindowBorder | ||
KeyEvent | ||
LineBorder | ||
ListItem | ||
ListView | ||
Menu | ||
MenuItem | ||
MouseEvent | ||
PackConstraints | ||
PackLayout | ||
Point | ||
Polygon | ||
Popup | ||
PopupItem | ||
Range | ||
Rect | ||
RootView | ||
ScrollBar | ||
ScrollGroup | ||
ScrollView | ||
Size | ||
Slider | ||
Sound | ||
TargetChain | ||
TextAttachment | ||
TextField | ||
TextParagraphFormat | ||
TextView | ||
Timer | ||
View | ||
WindowContentView |
The netscape.util package provides the necessary utility classes for the IFC, such as timers and archives. The complete list of classes, interfaces, and exceptions supported by netscape.util is shown in Table 56.2.
Classes | Interfaces | Exceptions |
Archive | Codable | CodingExceptionInconsistencyException |
Archiver | Comparable | DeserializationException |
ClassInfo | Decoder | NoSuchElementException |
ClassTable | Encoder | InconsistencyException |
Deserializer | Enumeration | |
FormattingSerializer | ||
Hashtable | ||
Serializer | ||
Sort | ||
Unarchiver | ||
Vector |
Together, the netscape.application and netscape.util packages form a library with an extensive object framework. As Table 56.3 shows, you can find objects for interface components, windowing, animation, and much more.
Framework | Description |
Animation | Enables advanced animation with line art and images; includes methods for buffering, flicker control, and transparency. |
Application Components | Provides key application components such as buttons, checkboxes, radio buttons, and text fields. |
Composite Components | Creates complex interface components such as file choosers, font choosers, and color choosers. |
Drag-and-Drop | Enables drag-and-drop features among components of an application. |
Event Drawing | Provides essential event-handling methods and allows objects called by an event to draw themselves. |
Multifont Text/Image Object | Allows for the display of multiple fonts in text elements; also allows for the display of embedded images. |
Object Persistence | Allows objects to maintain their state so that they can be reused later to initialize an application with user preferences. |
Timers | Enables multitasking without having to use multithreading. |
Windowing | Allows you to use internal and external windows. |
To compile and run Java programs that use IFC classes, you need a developer environment. The developer environment is found in the IFC SDK, which includes documentation, reference resources, and examples. You should install a developer environment on the system you plan to use for the development of IFC-enhanced Java programs.
If you just want to run Java programs that use IFC classes, you need a user environment. The IFC user environment is included with Netscape Communicator version 4.0 and later. However, you can install the IFC on any system to which Java has been ported. All you need is Java, a Java-compatible browser, and the IFC user download.
To obtain the IFC SDK or IFC user download, visit the Web page shown in Figure 56.2. The URL for the IFC Developer Central is http://developer.netscape.com/library/ifc/../index.html. Netscape archived the IFC files using several different compression formats (such as zip, gzip, and tar). Because the IFC is written completely in Java, you do not have to download different archive files for different systems.
The sections that follow look at the installation process by platform. There are separate installation sections for UNIX, Windows 95, Windows NT, and Macintosh systems. After you read the setup procedures for your system, jump ahead to the section called "Creating IFC-Enhanced Applets and Applications."
Keep in mind that the installation process is similar regardless of whether you plan to install a user environment or a developer environment. The key difference is that you use different filenames to retrieve and install the IFC archive file.
Netscape's IFC Developer Central Web page.
The IFC archive file you probably want to use for UNIX systems is the one compressed using gzip and tar. After you obtain the IFC archive, check to make sure that the size of the file you downloaded matches the file size listed on the Web site. If the file sizes are not identical, your file may have been corrupted during download. In that case, delete the file from your system and download the IFC archive again.
After you move the archive file to the base directory you want to use for installation (for example, /home/users), you can unzip and unpack the archive using the following command:
gunzip ifc60.tar.gz | tar xf -
Next, you have to let your system know where you installed the IFC class files. To do this, you use the CLASSPATH environment variable. CLASSPATH tells the Java interpreter and compiler where to look for your class files. When you installed Java, you probably assigned a value to the CLASSPATH variable. Do not remove this value; simply add another file path for the IFC classes.
C shell users will want to edit the .cshrc file in their home directory and update the statement that sets the CLASSPATH variable. If you installed the IFC class files in $HOME/ifc11/classes, you can update the CLASSPATH variable as follows:
setenv CLASSPATH java/classes:java/lib/classes.zip:$HOME/ifc11/classes
If the CLASSPATH variable is not set in your .cshrc file, enter only the path to the IFC files, as shown here:
setenv CLASSPATH $HOME/ifc11/classes
For these changes to take effect in the current command-tool or shell environment, you must source your .cshrc file or enter the setenv command at the shell prompt. This action updates the current environment settings.
If you are using the Bourne shell as your main UNIX shell, you can set the CLASSPATH in your .profile file. Do this by editing the .profile file in your home directory and updating the statements that set and export the CLASSPATH variable's path, as shown here:
CLASSPATH=java/classes;java/lib/classes.zip;$HOME/ifc11/classes export CLASSPATH
For these changes to take effect in the current command-tool or shell environment, you must set the CLASSPATH variable and export it from the command line, like this:
CLASSPATH=$HOME/ifc11/classes;export CLASSPATH
The IFC archive file you probably want to use for Windows 95 systems is the one that is zipped. After you obtain the IFC archive, check to make sure that the size of the file you downloaded matches the file size listed on the Web site. If the file sizes are not identical, your file may have been corrupted during download. In that case, delete the file from your system and download the IFC archive again.
To install the IFC from the MS-DOS prompt, follow these steps:
move ifc60.zip c:\
4. Unzip the archive file with an unzip utility that supports long filenames. Be sure to extract the directory structure.
After installing the IFC, update your AUTOEXEC.BAT file so that your computer can find the IFC class files. To do this, type the following at the DOS prompt:
EDIT C:\AUTOEXEC.BAT
Now you have to let your system know where you installed the IFC class files. To do this, use the CLASSPATH environment variable. CLASSPATH tells the Java interpreter and compiler where to look for your class files. When you installed Java, you probably assigned a value to the CLASSPATH variable. Do not remove this value; simply add another file path for the IFC classes.
If you installed the IFC under the C:\ directory, update the line that sets the CLASSPATH variable as follows:
SET CLASSPATH=C:\JAVA\LIB\CLASSES.ZIP;C:\ifc11\classes;
When you are finished, save and close your AUTOEXEC.BAT file. If you reboot your computer, you ensure that the working environment is set for all future sessions.
The IFC archive file you probably want to use for Windows NT systems is the one compressed using zip. After you obtain the IFC archive, check to make sure that the size of the file you downloaded matches the file size listed on the Web site. If the file sizes are not identical, your file may have been corrupted during download. In that case, delete the file from your system and download the IFC archive again.
To install the IFC from the MS-DOS prompt, follow these steps:
move ifc60.zip c:\
4. Unzip the archive file with an unzip utility that supports long filenames. Be sure to extract the directory structure.
After installing the IFC, create a user environment variable called CLASSPATH. CLASSPATH tells the Java interpreter and compiler where to look for your class files. When you installed Java, you probably assigned a value to the CLASSPATH variable. Do not remove this value; simply add another file path for the IFC classes.
If the CLASSPATH variable already exists on your system, double-click the System icon in the Control Panel, select the user environment variable, and then update it as follows:
C:\JAVA\LIB\CLASSES.ZIP;C:\ifc11\classes;
If the CLASSPATH variable does not exist on your system, double-click the System icon in the Control Panel and create the user environment variable with the following value:
C:\JAVA\LIB\CLASSES.ZIP;C:\ifc11\classes;
NOTE: If you did not install the IFC to the recommended location, you must enter the proper file path.
The IFC archive file you probably want to use for Macintosh systems is the one that is zipped. After you obtain the IFC archive, check that the size of the file you downloaded matches the file size listed on the Web site. If the file sizes are not identical, your file may have been corrupted during download. In that case, delete the file from your system and download the IFC archive again.
Before you can install the IFC, you must decompress the IFC archive file with an unzip utility. For IFC 1.1, this action creates a folder called ifc11 under the installation folder.
Next, create the following folder in the System folder: Preferences | Netscape | Java | netscape-classes. Then copy the contents of the ifc11/classes folder into the netscape-classes folder. If the copy is successful, the netscape-classes folders should have folders called netscape | application and netscape | util.
NOTE: If you installed Netscape Communicator version 4.0 or later, these folders should already exist. In this case, all you have to do is check for the existence of the folders.
In Java 1.1, there is no way for system classes to look up an applet's class by name. This presents a slight problem for IFC developers and requires a workaround. The way you implement the workaround depends on whether you are developing a standalone application or an applet.
NOTE: To compile IFC-enhanced programs, you must install the Java Development Kit and the IFC. If you have not already done so, do it now. To run IFC-enhanced programs, you must have the IFC and a Java-compatible browser.
Applications are standalone programs that do not run within a browser. When you develop an application that uses the IFC, start by creating a separate folder for the application. In this folder, create a file called NetscapeApplet.java with the contents shown in Listing 56.1. You can also find this code on the CD-ROM that accompanies this book.
import netscape.application.*; import netscape.util.*; public class NetscapeApplet extends FoundationApplet { public Class classForName(String className) throws ClassNotFoundException { return Class.forName(className); }
}
Then create the .java source files for your application in the same directory. Be sure that the main class is a subclass of the Application class and that you import netscape.application and netscape.util. Here are the statements that accomplish these goals:
import netscape.application.*; import netscape.util.*; public class myApplication extends Application { //main class definitions here
}
When you compile the application, compile all the .java files at the same time using the following command:
javac *.java
You can now run your application using the Java interpreter.
Applets are programs run within a browser. When you develop an applet that uses the IFC, start by following the steps outlined in the preceding section. If the applet compiles successfully, you can then create an HTML page to run the applet.
Unlike traditional applets, IFC-enhanced applets are not executed by their class name. Instead, you execute the applet by invoking the NetscapeApplet class with a parameter called ApplicationClass. The ApplicationClass parameter tells the IFC the name of the main class file for your application:
<APPLET CODE="NetscapeApplet"> <PARAM NAME="ApplicationClass" VALUE="AppName"> </APPLET>
In this syntax, AppName is the actual name of the main class file for the applet.
Listing 56.2 shows the code for a Web page with a script you can use to test the installation of the Netscape Internet Foundation Classes. This script uses the releaseName() function of netscape.application.Application to test for the presence of the IFC.
Load this page in a browser on your development or user platform to test the installation of the IFC. If a problem occurs, you will see an error similar to the one shown in Figure 56.3. You can also find this code on the CD-ROM that accompanies this book.
TIP: In the IFC check script, be sure to match the IFC version reference with the actual version you installed on your system. The script currently checks for IFC version 1.0. Keep in mind that the Netscape IFC is integrated into Netscape Navigator 4.0. This script is designed to be used with browsers other than Netscape Navigator 4.0.
<HTML> <HEAD> <TITLE>Check IFC Installation</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- browserName = navigator.appName window.onerror = errorMessage function errorMessage() { if (confirm("It appears you do not have the current version of Netscape IFC installed. \n\nWould you like to download the current release of IFC now?")) { window.open('http://developer.netscape.com/library/ifc/../index.html', '') } return true }function CheckIFC() { if (browserName.lastIndexOf('Netscape') != -1) { var app = netscape.application.Application var release = app.releaseName() if (release != "IFC 1.0") { errorMessage() return } window.confirm("Version: " + release + "\n\n of the IFC is properly installed on your system."); } else if (browserName.lastIndexOf('Microsoft Internet Explorer') != -1) { window.confirm("Verification does not work for Internet Explorer 3.0") } else { window.alert("Unable to determine if IFC has been installed properly.") } }// --> </SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFFF"> <DIV ALIGN="CENTER"> <H1>Check Netscape IFC Installation</H1> <P ALIGN=LEFT>You can check the IFC installation by clicking on the button below. If the IFC <EM>is</EM> installed properly, you will see a message telling you what version you currently have installed on your system. If the IFC <EM>is not</EM> installed properly, you will see an error message and have the opportunity to download the IFC from the IFC Developer Central.</P> <FORM> <INPUT TYPE="button" VALUE="Check IFC Installation" onClick="CheckIFC()"> </FORM> </DIV> </BODY> </HTML>
The IFC is not installed properly on this system.
The programmers at Netscape saw a window of opportunity to develop Java's user interface to its full potential--and they carried it 49 yards for a touchdown. As you have seen, the Netscape Internet Foundation Classes are not a replacement for Java classes; rather, the IFC is layered on top of Java's Abstract Windowing Toolkit and is designed to compliment it. To learn more about Netscape IFC, you may want to look for the Netscape ONE Developer's Guide (published by Sams Publishing). In this guide, you will find a detailed walk-through of all the frameworks in the IFC as well as applets and applications that use Netscape IFC components.
©Copyright, Macmillan Computer Publishing. All rights reserved.