[Appendix C] Platform-Specific Event Handling
Author: John Zukowski
Date: Thu Jul 31 14:17:05 1997

#

| Appendix C |

# C. Platform-Specific Event Handling

Contents:
The Results
Test Program

My life with Java began in September of 1995. I started on a Sun Sparc20 and have since used Java on Windows 95, Windows NT (3.51/4.0), a PowerMac, and an early version of a Java terminal. At the time I started using Java, it was in its alpha 3 release. Even before the beta release, the Internet crowd was hailing Java as the programming language for the next millennium, and people were lining up to take Sun's Java training classes.

Although Java has many important features, probably the most important is platform independence: you can compile a program once and run it anywhere. At least, that was the goal; and Java came impressively close to meeting that goal. However, there are some problems, particularly in the area of event handling. Java programs just do not act the same, from platform to platform, environment to environment. Even if you stay within Sun's Java Developer's Kit, you cannot take a program created on one platform, move it to another, and be guaranteed that it will react the same way to the user's interactions. To make matters worse, Netscape, the makers of the first run-time environment for beta API applets, Netscape, decided to take matters into its own hands with Navigator version 3.0; its version of AWT behaves slightly differently than the JDK's. On top of that, Navigator itself differs from platform to platform. Version 1.1 of the JDK introduces more idiosyncrasies, even as it resolves some others.

With more Java environments available, HotJava, Internet Explorer, and Java terminals to name a few, and new official extensions to AWT coming out, the differences are expanding, instead of contracting. Hopefully, there will be a day when this appendix can go away, completely. Until that time, I've tried to document the behavior of different run-time systems, on different platforms. If the platform is not included in this appendix, the source for a test program is. If you run the program on your platform and send the results to me at jaz@ora.com, they will be included in a future printing or provided online. The test program requires user-interaction, so please follow directions carefully. Between printings, the book's Web site will maintain the latest information at http://www.ora.com/catalog/javawt/. Only the results from using the latest releases of each platform are included in Table C.1.

## C.1 The Results

Table C.1 shows the events delivered to each component on the major platforms in Java 1.0. An OK in a particular entry means that the event is passed to Java from the component's peer; a dash means it is not.

Table C.1: Component Events in Java 1.0
Run-time | NN3.0 | NN3.0 | NN3.0 | SDK | JDK / Win95 / NT | JDK / Mac | JDK / Sun | IE3.0 / Win95 / NT | HJ / Win95 / NT | HJ / Sun
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
Button
KEY_PRESS | X | - | X | X | X | - | X | X | X | X
KEY_RELEASE | X | - | X | X | X | - | X | X | X | X
KEY_ACTION | X | - | - | X | X | - | X | X | X | X
KEY_ACTION_RELEASE | X | - | - | X | X | - | X | X | x | X
MOUSE_DOWN | X | - | - | - | - |  | - | - | - | -
MOUSE_UP | X | X | - | - | - |  | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | X | X | X | X | X | X | X | X | X | X
GOT_FOCUS | X | - | - | - | - | - | X | - | - | -
LOST_FOCUS | X | - | - | - | - | - | X | - | - | -
Canvas
KEY_PRESS | X | X | X | X | X | X | - | X | X | -
KEY_RELEASE | X | X | X | X | X | X | - | X | X | -
KEY_ACTION | X | X | - | X | X | X | - | X | X | -
KEY_ACTION_RELEASE | X | X | - | X | X | - | - | X | x | -
MOUSE_DOWN | X | X | X | X | X | X | X | X | X | X
MOUSE_UP | X | X | X | X | X | X | X | X | X | X
MOUSE_MOVE | X | X | X | X | X | X | X | X | X | X
MOUSE_ENTER | X | X | X | X | X | X | X | X | X | X
MOUSE_EXIT | X | X | X | X | X | X | X | X | X | X
MOUSE_DRAG | X | X | X | X | X | X | X | X | X | X
ACTION_EVENT | - | - | - | - | - | - | - | - | - | -
GOT_FOCUS | X | X | - | X | X | X | - | X | X | -
LOST_FOCUS | X | X | - | X | X | X | - | X | X | -
Checkbox
KEY_PRESS | X | - | X | X | X | - | X | X | X | -
KEY_RELEASE | X | - | X | X | X | - | X | X | X | -
KEY_ACTION | X | - | - | X | X | - | X | X | X | -
KEY_ACTION_RELEASE | X | - | - | X | X | - | X | X | x | -
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | X | X | X | X | X | X | X | X | X | X
GOT_FOCUS | X | - | - | - | - | - | X | - | - | -
LOST_FOCUS | X | - | - | - | - | - | X | - | - | -
Choice
KEY_PRESS | X | - | - | X | X | - | - | X | X | -
KEY_RELEASE | X | - | - | X | X | - | - | X | X | -
KEY_ACTION | X | - | - | X | X | - | - | X | X | -
KEY_ACTION_RELEASE | X | - | - | X | X | - | - | X | x | -
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | - | X | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | X | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | X | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | X | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | X | X | X | X | X | X | X | X | X | X
GOT_FOCUS | X | - | - | - | - | - | - | - | - | -
LOST_FOCUS | X | - | - | - | - | - | - | - | - | -
Label
KEY_PRESS | X | - | X | - | - | - | X | - | - | -
KEY_RELEASE | X | - | X | - | - | - | X | - | - | -
KEY_ACTION | X | - | - | - | - | - | X | - | - | -
KEY_ACTION_RELEASE | X | - | - | - | - | - | X | - | - | -
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | - | - | - | - | - | - | - | - | - | -
GOT_FOCUS | X | - | - | - | - | - | - | - | - | -
LOST_FOCUS | X | - | - | - | - | - | - | - | - | -
List
KEY_PRESS | X | - | - | X | X | - | X | X | X | -
KEY_RELEASE | X | - | - | X | X | - | X | X | X | -
KEY_ACTION | X | - | - | X | X | - | X | X | X | -
KEY_ACTION_RELEASE | X | - | - | X | X | - | X | X | x | -
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
LIST_SELECT | X | X | X | X | X | X | X | X | X | X
LIST_DESELECT | X | X | X | X | X | X | X | X | X | X
ACTION_EVENT | X | X | X | X | X | X | X | X | X | X
GOT_FOCUS | X | - | - | - | - | - | X | - | - | -
LOST_FOCUS | X | - | - | - | - | - | X | - | - | -
Scrollbar
KEY_PRESS | - | - | X | - | - | - | - | - | - | -
KEY_RELEASE | - | - | X | - | - | - | - | - | - | -
KEY_ACTION | - | - | - | - | - | - | - | - | - | -
KEY_ACTION_RELEASE | - | - | - | - | - | - | - | - | - | -
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | -/X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | -/X | X | - | - | - | - | - | - | - | -
SCROLL_LINE_UP | X | X | X | X | X | X | X | X | X | X
SCROLL_LINE_DOWN | X | X | X | X | X | X | X | X | X | X
SCROLL_PAGE_UP | X | X | X | X | X | X | X | X | X | X
SCROLL_PAGE_DOWN | X | X | X | X | X | X | X | X | X | X
SCROLL_ABSOLUTE | X | X | X | X | X | X | X | X | X | X
ACTION_EVENT | - | - | - | - | - | - | - | - | - | -
GOT_FOCUS | - | - | - | - | - | - | X | - | - | -
LOST_FOCUS | - | - | - | - | - | - | X | - | - | -
TextArea
KEY_PRESS | X | X | - | X | X | X | X | X | X | X
KEY_RELEASE | X | X | - | X | X | X | X | X | X | X
KEY_ACTION | X | - | - | X | X | X | X | X | X | X
KEY_ACTION_RELEASE | X | - | - | X | X | - | X | X | X | X
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | - | - | - | - | - | - | - | - | - | -
GOT_FOCUS | X | X | X | - | - | X | X | - | - | X
LOST_FOCUS | X | X | X | - | - | X | X | - | - | X
TextField
KEY_PRESS | X | X | X | X | X | X | X | X | X | X
KEY_RELEASE | X | X | X | X | X | X | X | X | X | X
KEY_ACTION | X | X | - | X | X | X | X | X | X | X
KEY_ACTION_RELEASE | X | X | - | X | X | - | X | X | X | X
MOUSE_DOWN | X | - | - | - | - | - | - | - | - | -
MOUSE_UP | X | X | - | - | - | - | - | - | - | -
MOUSE_MOVE | X | X | - | - | - | X | - | - | - | -
MOUSE_ENTER | X | X | - | - | - | X | - | - | - | -
MOUSE_EXIT | X | X | - | - | - | X | - | - | - | -
MOUSE_DRAG | X | X | - | - | - | - | - | - | - | -
ACTION_EVENT | X | X | X | X | X | X | X | X | X | X
GOT_FOCUS | X | X | X | - | - | X | X | - | - | X
LOST_FOCUS | X | X | X | - | - | X | X | - | - | X

Key:

IE

  Microsoft's Internet Explorer

HJ

  Sun's Hot Java Prebeta 1

JDK

  Java Developer's Kit 1.0.2 (appletviewer/Java)

NN

  Netscape Navigator

SDK

  Microsoft SDK

Sun

  Solaris 2.x (UNIX/Motif)

Yes, things changed again with the 1.1 release. Table C.2 shows which Java 1.0 events are generated for each component in Java 1.1. Fortunately, there is one clear improvement: the Java 1.1 event model promises much more uniform event processing, since it's largely under your control. For example, you can attach a `MouseListener` to a `Label` and receive mouse events that would not be generated with the 1.0 event model.

Table C.2: Java 1.0 Component Events in Java 1.1
Component/Events vs. | HJ/JDK | HJ/JDK
--- | --- | ---
Run-time/Platform | WinNT/95 | Sun
Button
KEY_PRESS | OK | OK
KEY_RELEASE | OK | OK
KEY_ACTION | OK | OK
KEY_ACTION_RELEASE | OK | OK
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | OK | OK
GOT_FOCUS | OK | OK
LOST_FOCUS | OK | OK
Canvas
KEY_PRESS | -- | --
KEY_RELEASE | -- | --
KEY_ACTION | -- | --
KEY_ACTION_RELEASE | -- | --
MOUSE_DOWN | OK | OK
MOUSE_UP | OK | OK
MOUSE_MOVE | OK | OK
MOUSE_ENTER | OK | OK
MOUSE_EXIT | OK | OK
MOUSE_DRAG | OK | OK
ACTION_EVENT | -- | --
GOT_FOCUS | -- | --
LOST_FOCUS | -- | --
Checkbox
KEY_PRESS | OK | OK
KEY_RELEASE | OK | OK
KEY_ACTION | OK | --
KEY_ACTION_RELEASE | OK | --
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | OK | OK
GOT_FOCUS | OK | OK
LOST_FOCUS | OK | OK
Choice
KEY_PRESS | OK | --
KEY_RELEASE | OK | --
KEY_ACTION | OK | --
KEY_ACTION_RELEASE | OK | --
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | OK | OK
GOT_FOCUS | OK | --
LOST_FOCUS | OK | --
Label
KEY_PRESS | -- | --
KEY_RELEASE | -- | --
KEY_ACTION | -- | --
KEY_ACTION_RELEASE | -- | --
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | -- | --
GOT_FOCUS | -- | --
LOST_FOCUS | -- | --
List
KEY_PRESS | OK | OK
KEY_RELEASE | OK | OK
KEY_ACTION | OK | OK
KEY_ACTION_RELEASE | OK | OK
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
LIST_SELECT | OK | OK
LIST_DESELECT | OK | OK
ACTION_EVENT | OK | OK
GOT_FOCUS | OK | OK
LOST_FOCUS | OK | OK
ScrollBar
KEY_PRESS | -- | --
KEY_RELEASE | -- | --
KEY_ACTION | -- | --
KEY_ACTION_RELEASE | -- | --
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
SCROLL_LINE_UP | OK | OK
SCROLL_LINE_DOWN | OK | OK
SCROLL_PAGE_UP | OK | OK
SCROLL_PAGE_DOWN | OK | OK
SCROLL_ABSOLUTE | OK | OK
ACTION_EVENT | -- | --
GOT_FOCUS | -- | OK
LOST_FOCUS | -- | OK
TextArea
KEY_PRESS | OK | OK
KEY_RELEASE | OK | OK
KEY_ACTION | OK | OK
KEY_ACTION_RELEASE | OK | OK
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | -- | --
GOT_FOCUS | OK | OK
LOST_FOCUS | OK | OK
TextField
KEY_PRESS | OK | OK
KEY_RELEASE | OK | OK
KEY_ACTION | OK | OK
KEY_ACTION_RELEASE | OK | OK
MOUSE_DOWN | -- | --
MOUSE_UP | -- | --
MOUSE_MOVE | -- | --
MOUSE_ENTER | -- | --
MOUSE_EXIT | -- | --
MOUSE_DRAG | -- | --
ACTION_EVENT | OK | OK
GOT_FOCUS | OK | OK
LOST_FOCUS | OK | OK

Key:

HJ

  Sun's Hot Java Prebeta 2

JDK

  Java Developer's Kit 1.1 (appletviewer/Java)

Sun

  Solaris 2.x (UNIX/Motif)

The Applet Tag |  | Test Program