This discussion will build on two previous discussions. First, it will extend the concepts discussed in the Java Events I discussion. It will do so, however, by continuing the programming task begun in the Java User Interface I discussion. Thus, the reader may wish to review both of those earlier discussions before reading further.
This discussion is presented with respect to Java 1.1. It will refer to the Java class hierarchy and, specifically, to AWT classes. A discussion based on Java 1.0 is also available.
The goal for this discussion is to add function to deal with the events generated by a user's interaction with the interface created in the Java User Interface I discussion.
Task
The task for this lesson is to continue building a basic user interface that appears in a separate window, rather than the browser's window. Previously, we built the interface, per se. Here, function is added to process events generated by a user interacting with menus and scrollbars.
Background
To establish a context for this discussion, review the code for producing the visual appearance for a basic application window.
Step 4
In this step, we will process events generated when a user selects a particular menu item.
Step 5
In step 5, events generated when a user moves or clicks on a scrollbar will be processed.
Step 6
In step 5, you could not see the effects of moving a scrollbar. Here, we add a simple drawn object to the display so that those effects can be seen.
Complete Applet
We can now put all the pieces together. The complete program is shown, including a run applet anchor.
Comment
You should now be able to create a basic Java program interface. You just have to add the code to do something useful. In subsequent discussions, we will consider additional user interface components and their layout on the display.
References
References useful for this discussion include the following:
- Sun's Java Development Kit (JDK)
- Sun's Java API
- Java API Class Hierarchy
- Source Code for JDK Packages