The language to which my friend was referring was Java 1.0 of course, which as he predicted shipped at the beginning of 1995. In late January of 1995, I connected to Sun's World Wide Web site and pulled down the first version of the Java JDK, and immediately began tinkering. Though still ignorant of the overall vision of Java, I was completely impressed with the platform independence and the speed at which I could build relatively complex prototypes. In these early stages I viewed Java as a replacement for Microsoft's Visual Basic as a prototyping tool; however, I was soon to appreciate the capabilities of this new language. Java 1.0 was still far from that Utopian software world that I searching for, but it demonstrated some real promise as an object oriented language and Sun's commitment to future enhancements convinced me that Java was the environment for me. In spite of the many skeptics around me, I was hooked.
I continued to use Java 1.0, noting its weaknesses and doing my best to work around them. I eventually came to realize some serious limitations in Java, but when I was almost ready to give up on the language, Sun released Java 1.1, featuring a totally new event model, and offering significant new features like internationalization and keyboard support. As an early technology adopter, I naturally downloaded the 1.1 release and my confidence in Java was renewed. Applications that crawled in the Java 1.0 Virtual Machine (VM) screamed once adapted to the new event model. However, like many other early adopters, I became exceedingly annoyed with the lack of power available to me through AWT. Still I persisted because in my mind Java's potential was apparent.
My conviction to Java continued, and in April 1997, I attended my first JavaOne conference quickly getting lost among the thousands of other attendees. The conference spanned all levels of developer expertise; so much of what I saw was old news to me. However I started hearing many people (mostly Sun employees) talking about something code-named "Swing". The as yet unreleased Swing was Sun's attempt at enhancing the Abstract Windowing Toolkit (AWT) and standardizing user interface components for future versions of Java. Discarding my original plans for the conference, I instead attended every session concerning Swing so I could learn more about Sun's new class library. Most of what I saw was just smoke-and-mirrors, but a few of the Swing demos caught my eye.
Introduction xiv By June 1997, Sun finally made a public alpha release of Swing available, coinciding with the start of a software project for which I wanted to employ Java. After considering several user interface (UI) class libraries from third party vendors, and also after completely disregarding Sun's warnings that the API would change, I decided to take a big risk and use Swing. Through several subsequent alpha and beta releases of Swing, my project paralleled its progress. Each time Sun offered up a new release, I had to spend a day fixing code broken by the changes they made. It was often frustrating, but I was steady in my resolve to integrate Swing into my application.
In the final analysis, my persistence paid off. My application shipped about the same time that Sun published the final release of Swing and received a very positive response from my peers. While still basking in my success I began to realize that I had invested a significant number of hours learning to make effective use of the Swing classes. So as an early technology adopter that has successfully conquered the learning curve, I decided to share this knowledge with all others that will follow now that the Swing technology is in the mainstream. The results of my efforts have been compressed into the pages of this book, and it is my sincerest hope that it helps smooth out some of the bumps that developers may hit when starting to use Swing.
In late February 1998, Sun shipped the finished Swing code; however Swing is just a small part of a larger group of technologies named Java Foundation Classes, or JFC. For developers using Java 1.1, JFC is available for download as a separate package from Sun's Web site. Java 1.2 users will discover that JFC is integrated into the Java runtime, so no additional installations are required.
Who is the Intended Audience?
This book is intended to help all types of Java developers who want to build user interfaces with Java, regardless of their level of expertise. This book is not a Java tutorial, so if you are a novice, you will certainly require some additional references to assist with the basic language syntax. In the appendices of this book you will find several good Java language resources. If you are an expert user, this book will hopefully become a "bible" that you can keep close at hand, referring to it when you hit a real snag.
Before we begin, I should describe my assumptions of you. Regardless of your level of expertise, I will assume that you have some experience building simple applications and/or applets with version 1.1 (or later) of Java. I have dedicated one of the early chapters of this book to act as a Java AWT refresher course, but it is by no means a complete tutorial for the language. This chapter will serve only to help contrast Java as it was with AWT to Java as it now exists with Swing.
Since the last chapter of this book will discuss optimization of Java code using multithreading, I will further assume the you have a solid understanding of how to write Java code with threads and the inner workings multithreading in general. Multithreading is a very complex mechanism, which can be either your most indispensable optimization tool or your worst debugging nightmare. You must exhibit extreme caution when writing multithreaded applications, and though we will examine multithreading from the Swing perspective, this book will not help you understand the pitfalls that multithread can introduce into a Java application.
Finally I will assume that you possess a thirst to learn. Though this book will cover some advanced topics related to Swing, there will still be much to learn on your own. Swing is brimming with interesting classes that can save you hours of work, but to fairly describe each individual class would require much more paper than you will find in this book. Don't be afraid to throw together some small test programs to test aspects of the Swing classes that you do not immediately understand.
How is This Book Organized?
This book consists of three parts. We begin with a bit of background on Java, and Swing, then learn about the basic user interface functionality, and finally examine some of the more advanced capabilities of Swing. I've also included a chapter to help you with optimization.
The book is organized as follows:
Part I contains all of the information you require to get started with Swing, including a description of the software packages you need and how to set them up. We will also have a quick Java refresher course for those who need it. Finally we will examine the architecture of Swing and start to talk about some of the advanced capabilities it has to offer.
Part II contains details about the typical classes you will utilize in the process of creating your own Swing applications. We will look at each of the common components and how to best use them, as well as techniques that can extend and enhance them to better suit your needs.
In Part III we look at more advanced topics. This part describes how to create components with a custom look and feel, and we will also take a look at several ways to make your Java code run faster.