Java Reference
In-Depth Information
Use the delegation event model
Know the remaining Java keywords
T eaching the elements of the Java language is the primary goal of this topic, and in this
regard, we are nearly finished. The preceding 14 chapters have focused on the features of
Java defined by the language, such as its keywords, syntax, block structure, type conver-
sion rules, and so on. At this point, you have enough knowledge to write sophisticated, use-
ful Java programs. However, there are two fundamental parts of Java programming that are
not defined by keywords, but by API classes and specialized techniques. These are applets
and events.
Be forewarned: The topics of applets and event handling are very large. Full and detailed
coverage of either is well beyond the scope of this topic. Here, you will learn their funda-
mentals and see several examples, but we will only scratch the surface. After finishing this
chapter, however, you will have a foundation upon which to build your knowledge.
This chapter ends with a description of the remaining Java keywords, such as instanceof
and native , that have not been described elsewhere in this topic. These keywords are used
for more advanced programming, but they are summarized here for completeness.
Applet Basics
Applets differ from the type of programs shown in the preceding chapters. As mentioned in
Chapter 1 , applets are small programs that are designed for transmission over the Internet
and run within a browser. Because Java's virtual machine is in charge of executing all Java
programs, including applets, applets offer a reasonably secure way to dynamically down-
load and execute programs over the Web.
Before we begin, it is necessary to explain two general varieties of applets: those based
on the Abstract Window Toolkit (AWT) and those based on Swing. Both the AWT and
Swing support the creation of a graphical user interface (GUI). The AWT is the origin-
al GUI toolkit and Swing is a lightweight alternative. This chapter describes AWT-based
applets. (Swing is introduced in Chapter 16 . ) It is important to understand, however, that
Swing-based applets are built upon the same basic architecture as AWT-based applets. Fur-
thermore, Swing is built on top of the AWT. Therefore, the information and techniques
presented here describe the foundation of applet programming and most of it applies to
both types of applets.
Prior to discussing any theory or details, let's begin by examining a simple applet. It per-
forms one function: It displays the string "Java makes applets easy." inside a window.
Search WWH ::




Custom Search