Register your product to gain access to bonus material or receive a coupon.
The only start-to-finish guide to Java event handling.
Efficient event handling is key to creating powerful, GUI-based Java software. Java Event Handling is the first Java book to focus entirely on event handling, from the absolute basics to state-of-the-art techniques. Expert Java developer Grant Palmer presents an in-depth introduction to the Java event model, showing how event handling has evolved to provide greater power and control, and demonstrating how to take full advantage of it. Coverage includes:
Whatever your Java experience, Java Event Handling delivers the expert insights and practical guidance you need to supercharge virtually any GUI-based application.
Acknowledgments.
Introduction.
A Roadmap for this Book. A Note on the Code Examples. What This Book is Not.
I. THE BASICS.
1. An Introduction to Java Events.What Is an Event? Local Versus Distributed Events. The Evolution of Java Event Handling. The Java Event Model. The Java 1.0 Event Model. The Java 1.1 Event Model.
2. The Java Event Life Cycle.Event Life Cycle Methods. Basic Event Life Cycle Methods from the Component Class. Event Processing Methods. Methods to Fire Events. Deprecated Methods from the Component Class. Event Life Cycle Methods Defined in the Component Subclasses.
3. Event Classes.Event and Support Class Hierarchy. Low-Level Versus High-Level Event Types. A Description of the Event Classes in the J2SE. The EventObject Class. The AWTEvent Class. Low-Level Event Classes Defined in the java.awt.event Package. High-Level Event Classes Defined in the java.awt.event Package. Special Event Classes Defined in the java.awt.event Package. Low-Level Event Classes Defined in the javax.swing.event Package. High-Level Event Classes Defined in the javax.swing.event Package. High-Level Event Interfaces Defined in the javax.swing.event Package. Event Support Classes Defined in the javax.swing.event Package. Event and Support Classes Defined in the java.beans Package. Event Classes Defined in the javax.swing.text.html Package. Event Support Classes Defined in the javax.swing.undo Package. Other Event Classes Defined in the J2SE. User-Generated Events. User-Defined Events.
4. Event Listeners.A Brief Review of Interfaces. Event Listener Interfaces in the J2SE. EventListener Interface. Listener Interfaces Contained in the java.awt.event Package. Listener Interfaces Contained in the javax.swing.event Package. Listener Interfaces Contained in the java.beans Package. Other Listener Interfaces Defined in the J2SE. Event Listener Objects. Creating an Event Listener. Method 1: Have a GUI Component Serve as the Event Listener. Method 2: Implement the Event Listener as a Separate Class. Method 3: Implement the Event Listener as an Inner Class. Method 4: Implement the Event Listener as an Anonymous Inner Class. Listener Adapter Classes. Listener Adapter Classes Contained in the java.awt.event Package. Listener Adapter Classes Contained in the javax.swing.event Package. User-Defined Event Listener Interfaces. Connecting an Event Source to an Event Listener. Disconnecting an Event Source from an Event Listener. The getListeners() Method. Event Listener Manager Classes. AWTEventMulticaster Class. EventListenerList Class.
5. Event Handling Odds and Ends.Determining the Event Source. Consuming Events. Event Consumption Methods. The Event Queue. EventQueue Class. The Event-Dispatching Thread. Running Code in the Event-Dispatching Thread.
II. A JAVA EVENT REFERENCE.
6. Event Classes and Interfaces.ActionEvent Class. ActiveEvent Interface. AdjustmentEvent Class. AncestorEvent Class. AWTEvent Class. CaretEvent Class. ChangeEvent Class. ComponentEvent Class. ContainerEvent Class. DocumentEvent Interface. DocumentEvent.ElementChange Interface. DocumentEvent.EventType Class. EventObject Class. FocusEvent Class. HierarchyEvent Class. HTMLFrameHyperlinkEvent Class. HyperlinkEvent Class. HyperlinkEvent.EventType Class. InputEvent Class. InputMethodEvent Class. InternalFrameEvent Class. InvocationEvent Class. ItemEvent Class. KeyEvent Class. ListDataEvent Class. ListSelectionEvent Class. MenuDragMouseEvent Class. MenuEvent Class. MenuKeyEvent Class. MouseEvent Class. PaintEvent Class. PopupMenuEvent Class. PropertyChangeEvent Class. TableColumnModelEvent Class. TableModelEvent Class. TextEvent Class. TreeExpansionEvent Class. TreeModelEvent Class. TreeSelectionEvent Class. UndoableEditEvent Class. WindowEvent Class. Other Event Classes in the J2SE.
7. Event Support Classes.PropertyChangeSupport Class. SwingPropertyChangeSupport Class. UndoableEditSupport Class. VetoableChangeSupport Class.
8. Event Listener Interfaces.ActionListener Interface. AdjustmentListener Interface. AncestorListener Interface. AWTEventListener Interface. CaretListener Interface. CellEditorListener Interface. ChangeListener Interface. ComponentListener Interface. ContainerListener Interface. DocumentListener Interface. EventListener Interface. FocusListener Interface. HierarchyBoundsListener Interface. HierarchyListener Interface. HyperlinkListener Interface. InputMethodListener Interface. InternalFrameListener Interface. ItemListener Interface. KeyListener Interface. ListDataListener Interface. ListSelectionListener Interface. MenuDragMouseListener Interface. MenuKeyListener Interface. MenuListener Interface. MouseInputListener Interface. MouseListener Interface. MouseMotionListener Interface. PopupMenuListener Interface. PropertyChangeListener Interface. TableColumnModelListener Interface. TableModelListener Interface. TextListener Interface. TreeExpansionListener Interface. TreeModelListener Interface. TreeSelectionListener Interface. TreeWillExpandListener Interface. UndoableEditListener Interface. VetoableChangeListener Interface. WindowListener Interface. Other Listener Interfaces in the J2SE.
9. Listener Adapter Classes.ComponentAdapter Class. ContainerAdapter Class. FocusAdapter Class. HierarchyBoundsAdapter Class. InternalFrameAdapter Class. KeyAdapter Class. MouseAdapter Class. MouseInputAdapter Class. MouseMotionAdapter Class. WindowAdapter Class.
10. Event Life Cycle Methods.AbstractAction Class Methods. AbstractButton Class Methods. AbstractCellEditor Class Methods. AbstractListModel Class Methods. Button Class Methods. Checkbox Class Methods. CheckboxMenuItem Class Methods. Choice Class Methods. Component Class Methods. Container Class Methods. DefaultBoundedRangeModel Class Methods. DefaultButtonModel Class Methods. DefaultListCellRenderer Class Methods. DefaultListSelectionModel Class Methods. DefaultSingleSelectionModel Class Methods. JApplet Class Methods. JComboBox Class Methods. JComponent Class Methods. JDialog Class Methods. JEditorPane Class Methods. JFrame Class Methods. JInternalFrame Class Methods. JList Class Methods. JMenu Class Methods. JMenuBar Class Methods. JMenuItem Class Methods. JPopupMenu Class Methods. JProgressBar Class Methods. JScrollBar Class Methods. JSlider Class Methods. JTabbedPane Class Methods. JTextArea Class Methods. JTextField Class Methods. JTree Class Methods. JViewport Class Methods. List Class Methods. MenuComponent Class Methods. MenuItem Class Methods. PropertyChangeSupport Class Methods. Scrollbar Class Methods. SwingPropertyChangeSupport Class Methods. TextComponent Class Methods. TextField Class Methods. Timer Class Methods. VetoableChangeSupport Class Methods. Window Class Methods.
III. ADVANCED TOPICS.
11. Event Listener Manager Classes.AWTEventMulticaster Class. EventListenerList Class.
12. User-Defined Event Classes and Event Listeners.Creating a User-Defined EventListener. Creating a User-Defined Event Class. Defining a Component that Supports a User-Defined Event. Putting it All Together.
13. Putting It All Together.Stagnation Point Heating Rate Program. A Java Document Editor.
14. Distributed Events.Distributed Event Model. Remote Event Classes. RemoteEvent Class. RemoteDiscoveryEvent Class. RenewalFailureEvent Class. ServiceEvent Class. Remote Event Listener Interfaces. Remote Interface. RemoteEventListener Interface. Remote Event Listener Support Classes. EventRegistration Class.
Appendix: Java GUI Components and the Events They Generate.Welcome to the interesting world of Java events. What is an event? Events are JavaUs messengers, traveling from an event source to a final destination, carrying information about something that has taken place. Events are what allow graphical user interfaces (GUIs) to do what they are supposed to do. Events are central to the concept of implementing bound and constrained properties in a Java Bean. Events are also important in distributed applications such as those using Jini or JavaSpaces technologies.
Java event handling is an important subject but, unfortunately, most Java reference books donUt do a good job of covering it. There is so much in the wide world of Java to write about that general reference books tend to devote only a few dozen pages to events and event handling. The material also tends to be interspersed throughout the book. This book, however, is the complete reference on Java event handling. It is the only book on the market that focuses entirely on Java event handling. It is a definitive work on the subject, including not only a complete technical reference on the event classes and interfaces but also a detailed look at the Java event model itself.
A Roadmap for This BookThe book is divided into three parts. Part 1 goes over the basics of Java event handling. It starts with a definition of what an event is and what it does. A history and description of the Java event model is presented. The Java event life cycle is described, telling what happens to an event from the time it is generated to when it reaches its final destination. The concept of an event listener is introduced. Finally, Part 1 covers some useful topics, such as the event queue and the event dispatching thread, that are basic to Java event handling.
Part 2 of the book is a complete technical reference for the event classes and interfaces contained in the Java Platform 2 Standard Edition (J2SE), from ActionEvent to WindowListener and everything in between. The information provided for each class or interface includes the syntax, the package it belongs to, the class or interface hierarchy, when it was introduced to the Java API, and the constructors, fields, and methods the class or interface defines. Each section is completely self-contained to provide "one-stop-shopping" for all information about a given class or interface, including a description of the fields and methods inherited from other classes or interfaces. Part 2 should answer all of your questions about what a class or interface can do and how to use it.
Parts 1 and 2 of this book will give you a solid understanding of Java event handling. The elements covered in Parts 1 and 2 are the things you will use in most of your programming work. In Part 3, we delve into some more advanced topics. These advanced topics are things you may not use very often, but they can be very powerful (and fun) to work with and can be used to customize the event handling aspects of a given code. The event listener manager classes are detailed. These classes are normally used by the system but can be accessed by the programmer to create new event classes and/or event-generating objects. The process for creating user-defined event classes and interfaces is described.
Part 3 also demonstrates how we can take everything we have learned and develop a couple of "real-world" GUI applications. We will have to make programming design decisions on how to implement the event handling sections of our code. The final section of Part 3 discusses the concept of a distributed event. Up to this point, the book has dealt with local events. These are events generated by an application running on a single machine using a single Java Virtual Machine (JVM). Distributed or Web-based applications might run on multiple platforms using multiple JVMs. Java provides a framework for the generation, transmission, and processing of events generated by a remote source.
The book also includes a handy appendix that lists the event-generating objects provided by the J2SE API. The list details the events each object can generate and how it generates them. The list not only includes all of the GUI components and containers, but also details the event-generating capabilities of the various models, documents, and other event-generating objects. For instance, if you want to know if a JTextField object can generate a TextEvent, the appendix will tell you.
A Note on the Code ExamplesLike any programming language, the best way to learn Java is by example, and this book supplies a lot of them. They are written as complete standalone applications. There are no code fragment examples, as these can be misleading and not show the whole picture. Most of the examples, particularly the ones in Parts 1 and 2 of the book, are intentionally simple, straightforward programs. They are easy to follow and are intended to demonstrate one or two key elements of an aspect of Java event handling without a lot of extra code to clutter things up.
The examples are all compiled and run in a similar fashion. For instance, to create the byte code for the SimpleExample.java, program you would type
javac SimpleExample.java
To run the example, you would then type
java SimpleExample
You are encouraged to try the examples out. Most of them are short enough so that you can type them in yourself if you want to, or you can access the examples by copying them from the CD-ROM included with this book.
You are also encouraged to play around with the examples. Change some things and see what happens. Just as you canUt learn how to swim without getting your feet wet, you canUt really gain an understanding of Java event handling, or Java in general for that matter, without writing or modifying some code.
With the exception of the remote event example in Part 3, all of the examples in this book use the J2SE API. You should have Java Development Kit (JDK) version 1.3, as many of the examples use classes and methods that were introduced in version 1.3. The Java Software Development Kit, which includes everything you will need for most of the examples, can be downloaded from the Sun Web site at http://java.sun.com
. The remote event handling example also requires that you install Jini on your system. For more details on this, see Part 3 of this book.
Now that we have spoken about what the book is, letUs talk briefly about what it is not. This book is not a beginning tutorial on Java and does assume some (although not a lot) of Java experience. You should be familiar with basic object-oriented principles, such as classes, inheritance, constructors, and so on. You should know about the different types of access, what they mean, and how to use them. You should know what the "this" keyword means and about inner and anonymous inner classes. Beyond this, it is probably useful to have at least an elementary understanding of the classes and interfaces contained in the core Java packages.
This book is also not a reference on AWT or Swing GUI components. These components are used in every example, but they are pretty much presented and used without explanation. Most of the examples use the GUI components in a simple, straightforward manner. If you have some prior experience with the GUI component classes, it should be clear what is being done and why. If anything looks confusing to you, consult a good Swing or AWT reference for illumination.