Home > Store

Java Event Handling

Register your product to gain access to bonus material or receive a coupon.

Java Event Handling

Book

  • This product currently is not for sale.
Not for Sale

Description

  • Copyright 2002
  • Dimensions: K
  • Pages: 624
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-041802-1
  • ISBN-13: 978-0-13-041802-9

The only start-to-finish guide to Java event handling.

  • Unlocks the power of Java event handling to enhance GUI development
  • Teaches basic skills and advanced event programming techniques
  • Provides complete technical references to all Java events
  • Stand-alone examples demonstrate the potential of Java events
  • Covers event classes, interfaces, the Java event model, and more!

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:

  • Local and distributed events: differences, similarities, and practical
  • techniques
  • Detailed technical reference to all Java events: event classes,
  • listener interfaces, support classes, lifecycle methods, and more
  • Advanced techniques: event listener manager classes, user-defined
  • event classes, event listeners, and more
  • Dozens of practical, easy-to-adapt code examples

Whatever your Java experience, Java Event Handling delivers the expert insights and practical guidance you need to supercharge virtually any GUI-based application.

Sample Content

Table of Contents



Acknowledgments.


Introduction.

A Roadmap for this Book. A Note on the Code Examples. What This Book is Not.



About the Author.

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.
Index.

Preface

Introduction

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 Book

The 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 Examples

Like 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.

What This Book Is Not

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.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020