Chapter 7: Implementing an Animator Component Using the Java Event Model

 < Day Day Up > 



7.1 Introduction

The Java Event Model is a ubiquitous way to handle communications between asynchronous activities. This model is used to implement the Java AWT but is also designed to be a generic method of passing events between asynchronous activities, such as threads. Because the Java Event Model was designed as a generic component, it has wide applicability for asynchronous activities that must be coordinated. Because it was designed to take advantage of the Java programming language, it integrates well with the Java language, and it is particularly useful when combined with other facilities in Java (such as RMI) to write programs distributed across a number of computers, such as chat programs, multiplayer games, or even Web servers.

This chapter explains the Java Event Model by creating a visual animator component. The process of building this animator component begins with a very simple animation program to show how animation can be achieved using the Java AWT and Swing Components. This simple animator is then converted into a generic component that can be used to handle a number of different animation tasks. The code for this generic component is refined to handle potential race and deadlock conditions until it implements the complete Java Event Model, which is safe and deadlock free if used correctly.

The animator is an example of a generic component in that it uses a Java interface so that it can work with objects of any type, including objects that are asynchronous activities such as threads. How to use the animator in procedural programs is also addressed in this chapter. Applying the animator to concurrent objects requires a better understanding of the nature of the interaction between the animator and other asynchronous activities and is covered further in Chapter 8.

The Java Event model that is presented in this chapter occurs frequently throughout the remainder of the book. It will prove especially useful in situations when passive objects must be linked with active objects at runtime — for example, when ActionListeners need to be associated with Buttons. It is also useful when combined with other techniques (presented in later chapters), creating powerful paradigms that can be used to implement concurrent programs.



 < Day Day Up > 



Creating Components. Object Oriented, Concurrent, and Distributed Computing in Java
The .NET Developers Guide to Directory Services Programming
ISBN: 849314992
EAN: 2147483647
Year: 2003
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net