Revised: Wed May 11 15:54:45 CDT 2016
This page is included in the following Books:
Table of contents
- Preface
- Preview
- Discussion and sample code
- Run the program
- Summary
- Miscellaneous
- Complete program listing
- Figures
- Listings
Preface
This module is one in a collection of modules designed for teaching ITSE2317 - Java Programming (Intermediate) at Austin Community College in Austin, TX.
(Editor's note: As you read this module, you will see that it was originally written around 2003. However, despite many improvements in Javasince then, most of what was true then is still true in 2013.)
This module makes several references to my website, which is located at (External Link) .
Purpose of this module
This module explains anonymous classes from a practical viewpoint, including a comparison between anonymous classes and local classes.
Viewing tip
I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figuresand Listings while you are reading about them.
Figures
- Figure 1 . Syntax for anonymous classes.
- Figure 2 . Program GUI.
- Figure 3 . Class file names.
- Figure 4 . Screen output.
- Figure 5 . Screen output.
- Figure 6 . Screen output.
- Figure 7 . Screen output.
- Figure 8 . Screen output.
- Figure 9 . Screen output.
Listings
- Listing 1 . The controlling class.
- Listing 2 . Beginning of the GUI class.
- Listing 3 . Beginning of the BaldButton class.
- Listing 4 . The processMouseEvent method.
- Listing 5 . Beginning of anonymous inner class.
- Listing 6 . Overridden processMouseEvent method.
- Listing 7 . Register a MouseListener object.
- Listing 8 . Implementing the interface.
- Listing 9 . Registering a WindowListener on the Frame .
- Listing 10 . Complete program listing.
Preview
What can you include in a class definition ?
There are several different kinds of items that can be included in a class definition. As you learned in the earlier modules in this series, the listincludes:
- Static variables
- Instance variables
- Static methods
- Instance methods
- Constructors
- Static initializer blocks
- Instance initializers
Can also contain other class definitions
As you also learned in previous modules, a class definition can also contain the following kinds of inner classes: