HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
Event Handling.
Layout Managers.
Graphics, Colors & Fonts.
Image Manipulation.
Lightweight Components.
Data Transfer & Drag and Drop.
Double Buffering.
7966F-4
Graphic Java 2 is the most comprehensive guide to the Java Foundation Classes (JFC) available. Three volumes cover all aspects of the JFC providing java developers with the skills needed to build professional, cross platform applications that take full advantage of the Java Foundation Classes.
The AWT is the cornerstone of the Java Foundation Classes. Volume 1 provides detailed descriptions of every aspect of the AWT, including:
Java expert David Geary provides clear and in-depth explanations of both fundamental and advanced AWT concepts. The layout manager chapter, for example, is over 100 pages long and includes what readers have called the best explanation of GridBagLayout on the planet. A GridBagLab application on the CD lets you explore GridBagLayout on your own.
The accompanying CD-ROM includes all of the example code from the book, ready to run on Solaris(tm), Windows 95, Windows NT, and Macintosh along with the JDK(tm) for those platforms.
(NOTE: Each Chapter concludes with a summary.)
PART 1. INTRODUCTION: THE JAVA FOUNDATION CLASSES, THE AWT, APPLETS, AND APPLICATIONS.
1. Introduction.The Java Foundation Classes. The Abstract Window Toolkit. Peers and Platform Independence. Components—The Foundation of the AWT. Components, Containers, and Layout Managers.
2. Applets and Applications.Java Applets. Java Applications. Combining Applet and Application Code.
PART 2. GRAPHICS AND IMAGES.
3. Graphics.java.awt.Graphics. Graphics Parameters. The Graphics Coordinate System. Graphics References. More on Drawing and Filling Shapes. Translating a Coordinate System's Origin. Clipping. Graphics Modes. Creating a Graphics.
4. Colors and Fonts.Color Models. The java.awt.Color Class. System Colors. Fonts and FontMetrics.
5. Loading and Displaying Images.The Image Class and the Image Package. Image Producers and Image Observers. Loading and Displaying Images. Differences Between Applets and Applications. Waiting for an Image to Load. Painting Images a Scanline at a Time. MediaTracker. Animated GIFS. AWT Components as Image Observers. Creating Images. Loading Images as Resources.
6. Image Filtering.The ImageProducer Interface. The ImageConsumer Interface. How Image Producers and Image Consumers Interact. AWT Image Filters. ImageConsumer Properties. Implementing Custom Image Filters. Extending RGBImageFilter. Extending ImageFilter. Implementing the ImageConsumer Interface. An Introduction to Double Buffering.
7. Image Manipulation Without Filtering.Scaling and Flipping Images. Grabbing Pixels. Memory Image Source.
PART 3. EVENTS AND LAYOUT MANAGEMENT.
8. Inheritance-Based Event Handling (AWT 1.02 and Before).The Original AWT Event Model. Event Modifier Constants. Mouse Button Events. Of Mice and Buttons. Monitoring Mouse Events. Sensing Double Clicking. Action Events. Identifying Components by Label— Just Say No. Shortcomings of the Inheritance-Based Event Model.
9. The Delegation Event Model (AWT 1.1 and Beyond).The Delegation Event Model. The Big Picture. AWT Adapters. Component Events. Semantic Events. Event Adapters. Inner Classes. Firing AWT Events from Custom Components. Firing Custom Events from Custom Components. Dispatching Events and the AWT Event Queue. Active Events. Inheritance-Based Mechanism. Event Handling Design.
10. Components, Containers, and Layout Managers.The Big Three of the AWT. Layout Managers. Painting a Container's Components. Forcing a Container to Lay Out Its Components. Standard AWT Layout Managers. The GridBagLayout Layout Manager. Null Layout Managers. Custom Layout Managers.
PART 4. AWT COMPONENTS.
11. The AWT Component Class.Components. java.awt.Component. Component Properties. Deprecated Methods. Component Location, Bounds, and Coordinates. Component Preferred, Minimum, and Maximum Sizes. Component Visibility and Responsiveness. Components and Peers. Rendering Components. Components and Zorder. Components and Cursors. Components and Serialization. Components and Internationalization. Components and JavaBeans. Components and Tree Locking.
12. Basic Components: Labels, Buttons, Canvases, and Panels.Labels and Buttons. Canvases and Panels.
13. Item Selectables: Checkboxes, Choices, and Lists.Choices and Lists.
14. Text Components.java.awt.TextComponent. java.awt.TextField. java.awt.TextArea.
15. Scrolling: Scrollbars and Scrollpanes.java.awt.Scrollbar. java.awt.ScrollPane.
16. Windows, Frames, and Dialogs.java.awt.Window. java.awt.Frame. java.awt.Dialog.
17. Menus.The Menu Classes. A File Menu. Handling Menu Events. Tear-off Menus. A MenuBar Printer. A FrameWithMenuBar Class. Help Menus. Checkbox Menu Items. Cascading Menus. Dynamically Modifying Menus. Popup Menus.
18. Mouseless Operation and Printing.Mouseless Operation. Keyboard Traversal. Menu Shortcuts. Printing.
19. Lightweight Components.Introducing Lightweight Components. A Simple Lightweight Component. Lightweight Containers. Lightweight Components and Zorder. Lightweights and Their Graphics. Lightweights and Preferred Sizes.
PART 5. ADVANCED TOPICS.
20. Clipboard and Data Transfer.The java.awt.datatransfer Package. The Clipboard Class. The System Clipboard. Local Clipboards. Data Transfer Mechanism. Copying Images to a Clipboard. Transferring Custom AWT Components.
21. Drag and Drop.The java.awt.dnd Package. Drag Sources and Drop Targets.
22. Custom Dialogs.The Dialog Classes. WorkDialog. ButtonPanel. Postcard. MessageDialog. YesNoDialog. QuestionDialog.
23. Rubberbanding.The Rubberband Classes. The Rubberband Base Class. Rubberband Panel. Exercising the Rubberband Classes. Refactoring the Unit Test.
24. Double Buffering.Double Buffering and Animation. How Double Buffering Works. Draggable Lightweights and a Double Buffered Container.
25. Sprite Animation.The Participants. Sequences and Sprites. Playfield and DoubleBufferedContainer. Collision Detection. Exercising the Animation Package.
Appendix A: AWT Class Diagrams. Preface
The 1.2 JDK (Java Development Kit) offers vastly improved support over its predecessors for developing graphical user interfaces and graphical applets/applications in the form of the Java Foundation Classes. The Java Foundation Classes are represented by four APIs: AWT, Swing, Accessibility and the 2D API.
The Abstract Window Toolkit (AWT) is Java's original user interface toolkit that provides a basic set of components such as labels, buttons, scrollbars etc. The AWT also includes a great deal of infrastructure for graphical components such as a delegation event model, layout management, and support for data transfer and lightweight components.
Swing is a second user interface toolkit that is built on the AWT's infrastructure. Swing offers a much more extensive set of components than the AWT; Swing's 40 components outnumber the AWT by a 4:1 ratio. Some Swing components (labels, buttons, etc.) are designed to replace their AWT counterparts, whereas other Swing components provide extra capabilities not found in the AWT (trees and tables).
The Accessibility API allows developers to implement Java applets and applications that are accessible to users with disabilities. The Accessibility API can also be used to develop alternative interfaces for nomadic users, such as a hypothetical Java navigational system that tells drivers (instead of showing them with a map display) went to turn in an audible fashion.
The 2D API encompasses a number of major enhancements to the AWT's graphics model in terms of manipulating colors, shapes and images and text.
Why The AWT and Why This Book?
The 1.2 JDK comes with the Swing set of components which includes a complete set of lightweight replacements for the AWT's heavyweight components. As a result, a common misconception is that Swing is a replacement for the AWT, but that is not the case. Swing is built on top of the AWT, and in fact, every Swing component is a bonafide AWT component. Because Swing components are in fact AWT components, it is imperative to have a good grasp of how AWT components behave and a what makes the AWT tick.
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. No stone is left 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.
Graphic Java Content
The delegation 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 pop-up menus), image manipulation, graphics, fonts and fontmetrics, dialogs, text components, etc.
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. The details of the language are left to those books.
Internet Sources of Information
There are several online sources of information on Java. You can find online guides and tutorials on Sun's home page:
http://java.sun.com/
There is an active net newsgroup dedicated to Java:
comp.lang.java
There is also a mailing list where Java aficionados exchange ideas, questions, and solutions. For information about the mailing list, look on the World Wide Web at:
http://java.sun.com/mail.html
From these newsgroups and web sites, you'll be able to locate countless other resources, tutorials, Frequently-Asked-Questions (FAQs), and online magazines dedicated to Java. For updates about this book and information about other books in the SunSoft Press Java Series, look on the web at:
http://www.sun.com/books/books/Geary/Geary.html
For some cool graphics, take a look at:
http://www.pixelsight.com:80/PS/pixelsite/pixelsite.html
Conventions Used in This Book