"Linux Gazette...making Linux just a little more fun!"

Book Review: Netscape IFC In a Nutshell

By R. J. Celestino

Netscape quietly released its Internet Foundation Classes (IFC) in the spring of 1996. This free Java class library offers developers a welcome alternative to the lifeless GUI widgets and basic graphics provided in Sun's Abstract Windowing Toolkit (AWT). However, the IFC can be intimidating even for experienced Java developers. To effectively use the IFC, you must learn its event model and its container model, both of which differ from standard Java. Additionally, learning the IFL's classes and API is no small endeavor. Netscape IFC in a Nutshell helps, with good explanations, examples and a handy quick reference guide.

Netscape IFC in a Nutshell is written by Dan Petrich and David Flanangan. In the Nutshell tradition, it is not too big or intimidating. The cover graphic will surely lead IFC geeks to refer to it as ``the fish book''. It weighs in at around 350 pages, approximately 140 pages of which are the quick reference section. This same reference information is available in HTML format from Netscape. I think it is helpful to complement on-line documentation with a compact hard copy reference, and I'm sure we all agree that making notes in the margin of an HTML page can be a bit difficult.

The book is far more than an API reference. It takes you through the IFC classes in a logical and matter-of-fact manner. Numerous examples cover most of the important aspects of the IFC. The examples are typically small but effective. They are well focused on the topics at hand and help immensely with understanding. The book does not include a CD-ROM, which is too bad as it would make a nice addition to the book. As an alternative, O'Reilly and Associates could have provided space on their web site for on-line examples and running applets. Unfortunately, they didn't do that either, so be prepared to type in each example and code fragment by hand.

The authors begin with a high-level introduction to the IFC. They discuss its capabilities including the sophisticated GUI widgets, persistence mechanism and the visual construction tool Constructor. If you are not sure what the IFC is all about or if it's right for you, this section is very helpful.

The next topic is an introduction to the most basic class in the IFC, the Application Class. As an IFC user, I have noticed that the IFC often departs from traditional Java vernacular. The Application class is one example of many you will come across. Seasoned Java developers typically understand application to mean a stand-alone Java program, and applet to mean a restricted Java program that runs in a browser. Forget all that when using the IFC. Every running IFC program, be it stand-alone or applet, is an application. Don't worry though; it's all explained very simply in this chapter using the power of the venerable Hello World program.

Having straightened out what an application is, the book takes you through a good explanation of the IFC's View classes. View classes in the IFC are akin to the Container classes in standard Java, but with differences in both architecture and capabilities. The authors devote three chapters to a discussion of these classes. They make good use of examples to show you many of the important features, from tiling a bitmap on the background to drawing.

Users interact with GUIs using a mouse and keyboard. In Java, these devices make themselves known by generating events. The mechanism by which these events are made available to your program is known as the event model. The Java standard event model has evolved over its short lifetime. It began as an inheritance-based model, eventually maturing to the more powerful delegation-based model used today. The IFC uses a hybrid model. The chapter on mouse and keyboard events covers the inheritance-based model. The chapter on targets covers the IFCs implementation of delegation-style event handling. The details of using each type of event are discussed in reasonable detail. Numerous examples show how to code your own event processing. However, I felt that the authors should have contrasted the two styles better. In addition, it would be helpful if they offered some guidelines on when to use each model.

The book moves on to cover each widget in considerable detail. Remember that the IFC provides a replacement for every standard widget, so even items as simple as a push-button or text field have a new API. These chapters really drive home the power of these IFC widgets, making the traditional widgets from Sun look absolutely bland.

I found their treatment of scrolling particularly useful. The IFC provides a framework to support scrolling of text and graphics. While very powerful, understanding the details can be daunting. The authors present scrolling clearly and offer good illustrative examples. With the details in this chapter, you will be able to add scrolling to any application with ease.

Another excellent section is the one on layout managers. Layout managers are classes that help View classes decide upon the size and position of the widgets they contain. The IFC includes a powerful new layout manager, the PackLayout. The book covers this complex layout manager in excellent detail. Outside of this book, there is virtually no useful documentation on the true behavior of the pack layout.

Anyone who has ever written an applet that displays images will eventually reach the conclusion ``why don't they handle all of this mess for me?'' Netscape's engineers felt the same way, and they did something about it. In the chapters on images and animation, you will learn how simply your application can read and display image files (both GIFs and JPEGs). Creating animation is a simple matter as well. The book explains how the IFC handles threading, sequencing and double buffering. If you are interested in images and animation, these chapters will get you going quickly and painlessly.

In the Advanced Topics section, the authors cover the details of the TextView class, archives, and the free GUI builder Constructor.

The authors rightly spend a considerable amount of time discussing the TextView class. They show how to use TextView to display HTML documents, handle hyperlinks, open a mini editor and more. With all this versatility from a single component, it is a comfort to have clear explanations and examples to lead you.

The authors next discuss archives. Archives provide object persistence. Every class in the IFC can be archived to disk so that it can outlive the process that created it. The authors detail how to use IFC archives to read and write objects in a number of situations. They also discuss how to archive existing IFC classes and explain how to archive classes that you have created.

Finally, you will learn how to use Netscape Constructor. Unlike the rest of the IFC, Constructor is an application not a component. Perhaps this is why the chapter is so skimpy. Considering this chapter is in the ``Advanced Topics'' section, I would have expected more detailed information. Nonetheless, the chapter does provide some good information on few aspects of the elusive Constructor.

The GUIs that are created using the IFC are truly a pleasure to behold. The widgets, in stark contrast to their plain Java brethren, have a polished look and feel. Some of the components, such as TextView, are so powerful that they could be marketed on their own. Learning such a comprehensive class library can be downright scary. Netscape IFC in a Nutshell provides numerous easy to follow examples, detailed explanations and a quick reference guide.

Eventually, the IFC will be subsumed by the Java Foundation Classes (JFC), a joint venture between Sun and Netscape. But if you want beautiful user interfaces today, the IFC is the way to go, and Netscape IFC in a Nutshell is a great way to get you there.

Copyright © 1998, R. J. Celestino
Published in Issue 28 of Linux Gazette, May 1998