Java Events II

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.

The discussion will refer to the Java class hierarchy and, specifically, to AWT classes.

The goal for this discussion is to add function to deal with the events and actions 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 handle 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 this step, the issue of the particular Java class in which to trap events is considered. We would like to process actions and events within the applet, but to do so, we must trap them in some location within the class hierarchy where they will be seen and then direct them to the applet. One way to do this is to override the Frame class, trap them there, and then send them to overridden action or handleEvent methods in the applet.

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: