Synopsis:
Mastering the AWT. Back cover marked. Binding splitting near the back. No CD Rom.Softback, ex-library, with usual stamps and markings, in fair all round condition.
From the Inside Flap:
Preface to the Second Edition
The AWT has undergone an amazing metamorphosis between 1.02 and 1.1. The 1.1 version of the AWT has been fitted with an industrial-strength event model, and support has been added for: lightweight components, clipboard and data transfer, printing, desktop colors and mouseless operation. Many shortcomings of the original AWT have been dealt with in the 1.1 release; for example, the AWT now sports both popup menus and a scrollpane.
Perhaps more importantly, however, the 1.1 version of the AWT is much more solid than the 1.02 version. The 1.1 AWT, with the exception of a few bugs here and there, performs as advertised.
Perhaps the most exciting addition to the 1.1 AWT is support for lightweight components. Lightweight components are less resource intensive than their heavyweight counterparts, and can be transparent with an irregular (non- rectangular) border. Although the 1.1 AWT provides the infrastructure for implementing custom lightweight components, it does not provide any specific lightweight components. In a future release, the AWT will provide lightweight versions of all of the existing (heavyweight) components.
The second edition of Graphic Java is based on the 1.1.2 version of the AWT. 1.1.1 and 1.1.2 were both bug fix releases; the latter hit the streets just as we went to press.
AWT/GJT Coverage
For the second edition of Graphic Java we wanted to deemphasize discussion of the Graphic Java Toolkit. Some of the feedback we received from the first edition of Graphic Java was that the book leaned too much towards the GJT with not enough explicit coverage of the AWT.
We have worked hard to remedy this the second time around, by adding 10 new chapters spanning 350 pages, all of which deal exclusively with the AWT:
Delegation-Based Event Model (AWT 1.1 and Beyond)
The AWT Component Class
Basic Components: Labels, Buttons, Canvases, and Panels
Item Selectables: Checkboxes, Choices, and Lists
Text Components
Scrolling: Scrollbars and Scrollpanes
Windows, Frames, and Dialogs
Lightweight Components
Clipboard and Data Transfer
System Colors, Mouseless Operation, and Printing
Instead of being split evenly between AWT and GJT coverage, as was the case with the first edition, 70% of Graphic Java is now devoted exclusively to the AWT. Also much of the original coverage of the AWT that employed the GJT to illustrate concepts has been rewritten so that it no longer uses GJT components.
Layout manager coverage has been signficiantly beefed up. In our relentless pursuit to provide you with the best GridBagLayout discussion on the planet, 30 new pages dedicated to GridBagLayout have been added to the layout manager chapter.
All of the chapters covering the GJT have been updated, and a good percentage have been rewritten from the ground up, such as the chapter on GJT dialogs.
The Graphic Java Toolkit (GJT)
The Graphic Java Toolkit has undergone significant changes. The GJT's event handling, of course, has been updated to the new event model while other new features of 1.1, such as system colors, have been incorporated into the GJT.
The sprite animation package has been refactored. Sprites are now lightweight components that are animated on a playfield that is an extension of the new DoubleBufferedContainer class, whose forte is displaying lightweight components. A fair percentage of the GJT custom components are now lightweights.
The convenience dialogs have been revamped: they can now display a picture and a panel side-by-side.
Then there are new components: splash screens, bubble help, toolbox, work dialog, color and cursor choices, etc.
We tried to maintain the public interfaces of the original GJT whenever possible, but in some cases we had to make modifications. If you have code that uses the original GJT, it should be a fairly simple matter to slip in the 1.1 version of the GJT, provided that you are using the 1.1 JDK, of course.
GJT JavaBeans
The Graphic Java Toolkit will soon be available in a JAR. Watch comp.lang.java.announce for details.
For Mac Users
Graphic Java now supports the Macintosh!
The CD in the back of the book comes complete with a 1.02 version of the GJT, along with project files for both CodeWarrior and Cafe on the Macintosh. The 1.1 JDK for the Mac was not out when we went to press.
We were pleasantly suprised with the GJT on the Mac. Certainly the state of Java affairs on the Macintosh is greatly improved since the first edition of Graphic Java, and we have confidence that the 1.1 JDK on the Mac will prove to be solid as well.
So if you are a Mac user, here's the bottom line. All of the code discussed in Graphic Java has been implemented under 1.1, and therefore will not work on the Mac until the Mac 1.1 JDK comes out. When the Mac 1.1 JDK comes out, all of the code presented in Graphic Java should run as advertised on the Mac. The 1.02 version of the GJT is provided for those that want to get their feet wet using the 1.02 JDK, and also for anyone unfortunate enough to be unable to upgrade to 1.1.
Finally, we should note that we couldn't resist putting some Mac screenshots of GJT unit tests in the second half of the book. We should note that such screenshots are applets running under the 1.02 AWT on the Mac, and not under the 1.1 AWT as are the rest of the screenshots in the book.
Preface
Graphic Java is meant, first and foremost, to help you master the AWT. Both fundamental and advanced concepts of the AWT are fully explored in the pages that lie ahead. Each AWT component is examined in detail, and AWT Tips are provided to illuminate some of the AWT's dark corners. More than 50 custom components are dissected. We aim to leave no stone unturned.
What You'll Find Inside
After reading Graphic Java, you will have a thorough grasp of how the AWT is designed, and how to best take advantage of that design. The following is a sample of the coverage provided in the pages that lie ahead.
Peers
You will understand the peer architecture of the AWT, along with the pros and cons of the peer approach. For instance, you'll know which Component methods behave differently if invoked before a component's peer has been created, and what to do about it.
Clipboard and Data Transfer
You'll understand the data transfer model employed by the AWT, and how to utilize both local clipboards and the system clipboard. While the AWT only provides the ability to transfer strings to and from a clipboard, Graphic Java shows you how to put other data types on the clipboard, with examples of transferring both images and custom components.
Lightweight Components
In addition to being able to implement lightweight custom components, you'll also know how to drag them across a double buffered container, and even how to animate them on a playfield. You will understand how double buffering works, and why lightweight components should be displayed in a double buffered container. You will know the pitfalls of placing lightweight components in a container, and why lightweight containers must be manually fitted with a layout manager.
Layout Managers
You will have a complete grasp of layout managers, including the behemoth, GridBagLayout, and you will be able to implement custom layout managers with ease. You will understand how to force a container to layout its components, and why it is sometimes necessary to do so.
Internationalization and Serialization
You'll be able to internationalize a graphical user interface, and serialize both AWT components and their event listeners.
Scrolling
You will be able to scroll any number of components in a container by using a scrollpane. You'll also understand the limitations of the scrollpane class and why it is sometimes necessary to have a peerless scrolling framework. Of course, we'll discuss the implementation of such a scrolling framework from the Graphic Java Toolkit, which you are free to use for your own purposes.
Custom Components and Graphic Java
When discussing standard AWT components, we strive to take you one step further, usually by discussing the implementation of a custom component. For instance, when we cover windows, we will discuss the implementation of a splash screen, and when we explore text components, we'll look at field validation, both exit validation and on-the-fly validation. In addition to discussing dialogs in detail, five custom dialogs are examined.
The Graphic Java Toolkit
The Graphic Java Toolkit (GJT) is a collection of more than 45 custom components built using the AWT. The GJT is not a replacement for the AWT—instead it provides custom components that are not found in the AWT. The GJT is freely available; you can download it from:
sun/books/books/Geary/Geary.html
The GJT can be used in any product, even a commercial endeavour, as long as it is not sold as a standalone toolkit. See the license that comes on the CD for the legal details. See “Introducing the Graphic Java Toolkit” on page 559 for an introduction to the GJT.
Strategic Importance of Custom Components
All in all, more than 50 custom components are discussed in the pages ahead, such as: splash screens, bubble help, rubberbanding, sprite animation, image buttons, toolbars, custom dialogs, etc. The custom components are meant to illustrate the ins and outs of implementing custom components, while also providing you with a set of components you can use right alongside the components provided by the AWT.
Graphic Java Content
The 1.1 event model, lightweight components, clipboard and data transfer, desktop colors, mouseless operation, and printing are all thoroughly covered. You'll also find extensive coverage of scrolling, menus (including popup menus), image manipulation, graphics, fonts and fontmetrics, dialogs, text components, etc.
Extending the AWT
In Part 2 of the book, we present the Graphic Java Toolkit (GJT). In all, there are over 45 custom components in the GJT. Among these are components such as:
Image buttons and toolbars
Separators and bargauges
Etched and three-dimensional rectangles and borders
Image and component scrollers
Rubberbands
Convenience dialogs
The GJT also includes image filters and a package of classes for developing sprite animations. You are welcome to use and incorporate the GJT into your own program development.
In describing these custom components, we highlight lessons learned and reveal tricks of the trade for those who'll be developing their own custom components. Along the way, we hope to encourage good programming practices, using Java's object-oriented features to develop elegant, maintainable, and readable code. And we try to do these things in practical terms, so that you can see and learn from examples of real programs.
Audience
This book is written for object-oriented developers working in Java. There are numerous books explaining details of the Java language and how it works vis-a- vis Visual Basic, C, C++, etc. We leave details of how Java works to those books. If you are new to Java, you might want one of those books alongside Graphic Java.
The Graphic Java Toolkit
The CD that accompanies this book includes:
The complete source code for the Graphic Java Toolkit.
Unit test applets for all GJT components, including HTML files for unit test applets.
HTML documentation for all GJT classes
Numerous image files in .gif format developed by Pixelsite
Virtually all these programs are discussed throughout the book. Feel free to borrow, adapt, or extend these for your own purposes.
The Graphic Java Toolkit Package Structure
Table P-1 shows the GJT package structure.
Table P-1 GJT Package Structure
Package: gjt
Contents: This package contains the source files for many of the custom components discussed in Graphic Java.
Package: gjt.animation
Contents: This package contains a set of classes that support sprite animation.
Package: gjt.image
Contents: This package contains a set of classes that provide support for image manipulation such as bleaching or dissolving images.
Package: gjt.test
Contents: This package contains source code for all the component unit tests discussed in Graphic Java.
Package: gjt.rubberband
Contents: This package contains a set of classes that support rubberbanding—stretching lines and shapes over a backdrop without affecting the backdrop.
Internet Sources of Information
There are several online sources of information on Java.
For updates about this book and information about other books in the Sun Microsystems Press Java Series, look on the web at: sun/books/books/Geary/Geary.html
For some of the coolest looking graphics on the planet, take a look at: pixelsight:80/PS/pixelsite/pixelsite.html
Conventions Used in This Book
Table P-2 shows the coding conventions used in this book.
Table P-2 Coding Conventions
Convention: Class names have initial capital letters.
Example: public class LineOfText
Convention: Method names have initial lowercase and the rest of the words have an initial capital letter.
Example: public int getLength()
Convention: Variable names have initial lowercase and the rest of the words have an initial capital letter.
Example: private int length
Example: private int bufferLength
Convention: static variables begin with an underscore.
Example: protected static int _defaultSize = 2;
Note that, for the most part, we refer to methods without their arguments; however, we include the arguments when the discussion warrants including them.
Table P-3 shows the typographic conventions used in this book.
Table P-3 Typographic Conventions
Indicates that the accompanying code, command, or file is available on the CD that accompanies this book.
Typeface or Symbol: courier
Description: Indicates a command, file name, class name, method, argument, Java keyword, HTML tag, file content, or code excerpt.
Typeface or Symbol: bold courier
Description: Indicates a sample command-line entry.
Typeface or Symbol: italics
Description: Indicates definitions, emphasis, a book title, or a variable that you should replace with a valid value.
"About this title" may belong to another edition of this title.