Skip to main content

Section 4.2 The User Interface

The user interface is that part of the program that handles the input and output interactions between the user and the program. As an interface, it limits or constrains the manner in which the user can interact with the program.

Computer programs are just one of the many things that require a user interface. Virtually every device we use has one. For example, consider again the difference between the user interface of a digital versus an analog watch. On a digital watch, you have a display that tells you the time to the exact hour, minute, and second. On an analog watch, one with a sweep second hand, the time can never be displayed to the exact second. Similarly, on a digital watch there are buttons that let you set the time to the exact hour, minute, and second. On an analog watch, there is a small wheel that allows you to set the time only approximately. Thus, the user interface constrains the kinds of interactions that are possible between the user and the device.

With regard to our Java programs, one way to divide up the labor is to distinguish between the user interface and the computational functions. The role of the user interface is to transmit data back and forth between the user and the program. The role of the computational part of the program is to perform some kind of computation, in the broad sense of that term. The computation might be to play a game, or calculate a square root, or monitor a hospital patient. Figure 4.2.1 provides a generic picture of the relationship between the user interface and the computational object.

Figure 4.2.1. The user interface transmits data back and forth between the user and the program's computational objects.

In this chapter we focus our attention on the user interface side of the relationship shown in Figure 4.2.1. In subsequent chapters we will focus more on the computational side of the relationship. What we desire is an approach that lets us combine a computational object with any one of the three different kinds of user interfaces.

You have attempted of activities on this page.