Chapter 10: Handling Mouse and Keyboard Events
Note: this page applies to the now-obsolete first edition of the book. For
the second edition, please see
http://www.corewebprogramming.com.
This chapter of
Core Web Programming (pages 448-497) discusses the event-handling
mechanisms of Java 1.1 and 1.02.
Contents
Note that several of these require Java 1.1.
Reminder: Right click on the
link to the source code to save it on your local machine.
- Drawing circles where user clicks the mouse.
These examples illustrate various approaches to Java 1.1 event handling.
There are five similar versions:
-
handleEvent.java. An example of what the builtin
handleEvent method looks like in Java 1.02.
-
MouseDownFrame.java. An illustration of how events bubble
up through enclosing windows in Java 1.02.
-
MouseDownPanel.java. Supporting window used in MouseDownFrame.
-
CursorCanvas.java. Illustrates that you can change cursors
in windows in Java 1.02 by looking up the parent Frame. You
don't need to do this in Java 1.1 or 1.2 -- per-Component cursor
support is already built in.
-
CursorTest.java. Demonstrates the CursorCanvas
(also available on-line through
CursorTest.html).
-
EventPanel.java
-
Events.java. A Java 1.02 event reporter. Uses EventPanel
(also available on-line through
Events.html).
-
SimpleWhiteboard2.java. Java 1.1 version of an applet that
lets you do free-hand drawing.
(also available on-line through
SimpleWhiteboard2.html)
-
Whiteboard2.java. Enhancement to SimpleWhiteboard2 that
supports annotating the drawings with keyboard text.
(also available on-line through
Whiteboard2.html).
-
SimpleWhiteboard1.java. Java 1.02 version of an applet that
lets you do free-hand drawing.
(also available on-line through
SimpleWhiteboard1.html)
-
Whiteboard1.java. Enhancement to SimpleWhiteboard1 that
supports annotating the drawings with keyboard text.
(also available on-line through
Whiteboard1.html).
-
Mirror.java. A class that illustrates that you can
attach multiple listeners to the same component in Java 1.1,
plus consume events before the underlying component acts on them.
(also available on-line
through Mirror.html)
-
MouseReporter.java. Prints a summary of the mouse
events to the Java console
(also available on-line in a Java 1.1 capable browser
through MouseReporter.html).