The next few discussions will be concerned with building user interfaces in Java using the AWT. The emphasis will be on developing a familiarity with the different components that are available. We will look, first, at the components needed to build a basic application user interface. After that, we will add code to handle events. Finally, we will look at additional user interface components and at several different layout managers that can be used to arrange components on the display.
This discussion is presented with respect to Java 1.1. A discussion based Java 1.0 is also available.
User interface components are provided through the java.awt package. Most are subclasses of the
Component
class. The event handling interfaces and methods are included in the java.awt.event package.
Task
Out task is to build a basic interface for an applet, implemented as a separate window rather than being included within a browser's window. It will be built in three steps. It will include components such as menus and scrollbars, it will inlcude the necessary interface methods, but it will not do anything. We will add function to interpret users' actions, such as selecting a particular menu item, when
events
are discussed in more detail in a later lesson.Step 1
The first step is to build the basic framework for the interface. It will be built as a separate window, rather than as a panel contained within the applet window.
Step 2
After building the basic window, we will add menus to the top of the window.
Step 3
The third step is to build the
scrollbars
and a message display area.
References
References useful for this discussion include the following::